HTML | DOM getNamedItem() Method
The DOM getNamedItem() method in HTML is used to return the attribute node from the NamedNodeMap object.
Syntax:
namednodemap.getNamedItem( nodename )
Parameter’s Value: This method contains single parameter nodename which is mandatory. The nodename is retured from NamedNodeMap object.
Example:
<!DOCTYPE html> <html> <head> <title> DOM getNamedItem() Method </title> <script> /* main function */ function MyGeeks() { var ele = document.getElementsByTagName("button")[0]; var item = ele.attributes.getNamedItem("onclick").value; document.getElementById("geeks").innerHTML = item; } </script> </head> <body style = "text-align:center"> <h2>DOM getNamedItem() Method</h2> <p> Click on the button to know the value of onclick attribute </p> <button onclick = "MyGeeks()"> Click Here! </button> <p id="geeks"></p> </body> </html> |
Output:
Before click on the button:

After click on the button:

Supported Browsers: The browser supported by DOM getNamedItem() Method are listed below:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM hasFocus() Method
- HTML | method Attribute
- HTML | DOM normalizeDocument() Method
- HTML | DOM querySelectorAll() Method
- HTML | DOM insertAdjacentElement() Method
- HTML | DOM normalize() Method
- HTML | DOM addEventListener() Method
- HTML | DOM importNode() Method
- HTML | DOM hasAttributes() Method
- HTML | DOM querySelector() Method
- HTML | DOM getElementById() Method
- HTML | DOM fullscreenEnabled() Method
- HTML | DOM writeln() Method
- HTML | DOM Storage key() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



