Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM getNamedItem() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 returned from NamedNodeMap object. 
Return Value: It returns a  Node object, which  representing the attribute node with the specified name

Example:  

html




<!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 1
  • Edge 12
  • Internet Explorer 6
  • Firefox 1
  • Opera 12.1
  • Safari 1

My Personal Notes arrow_drop_up
Last Updated : 08 Jul, 2022
Like Article
Save Article
Similar Reads
Related Tutorials