Javascript examples for DOM:Element getAttributeNode
The getAttributeNode() method returns the attribute node by name as an Attr object.
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to return |
An Attr object, representing attribute node.
The following code shows how to Get the value of the class attribute node of an <h1> element:
<!DOCTYPE html> <html> <head> <style> .democlass {/*from w ww . j a v a 2 s. c om*/ color: red; } </style> </head> <body> <h1 class="democlass">Hello World</h1> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var elmnt = document.getElementsByTagName("H1")[0]; var attr = elmnt.getAttributeNode("class").value; document.getElementById("demo").innerHTML = attr; } </script> </body> </html>