Javascript examples for DOM:Attribute
The item() method returns the node at the specified index in a NamedNodeMap, as a Node object.
Parameter | Type | Description |
---|---|---|
index | Number | Required. The index of the node in the NamedNodeMap |
A Node object, representing the attribute node at the specified index.
The following code shows how to Get the name of the first attribute of a <button> element:
<!DOCTYPE html> <html> <head> <style> .example {/*from ww w .jav a 2s . c o m*/ color: red; padding: 5px; width: 150px; font-size: 15px; } .newClass { color: blue; padding: 15px; width: 250px; font-size: 18px; background-color: white; } </style> </head> <body> <button onclick="myFunction()" class="example">Test</button> <script> function myFunction() { var a = document.getElementsByTagName("BUTTON")[0]; a.attributes[1].value = "newClass"; } </script> </body> </html>