Javascript examples for DOM:Attribute
The getNamedItem() method returns the attribute node by name from a NamedNodeMap object.
Parameter | Type | Description |
---|---|---|
nodename | String | Required. The name of the node in the namedNodeMap |
A Node object, representing the attribute node with the specified name
The following code shows how to Get the value of the onclick attribute of a button element:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w. ja va 2 s. com*/ var a = document.getElementsByTagName("BUTTON")[0]; var x = a.attributes.getNamedItem("onclick").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>