HTMLCollection namedItem() Method

The namedItem() Method is used to return the element with having the specified ID, OR, name or content in an HTML element collection in the document.

Syntax:

HTMLCollection.namedItem(name)

OR



HTMLCollection[name]

Parameters: It contains the name as its parameters values which represent the ID OR name attribute that the user want to return.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>GeeksForGeeks</h1>
        <h2>HTMLCollection namedItem() Method</h2>
  
        <p id="GFG">
          The namedItem() method is used to return 
          the content of the element with the specified 
          ID or name Attribute values
        </p>
  
        <button onclick="Geeks()">Submit</button>
  
        <script>
            function Geeks() {
                var w =
                    document.getElementsByTagName("P").namedItem("GFG");
                alert(w.innerHTML);
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

After clicking on Submit:

Supported Browsers: The browser supported by HTMLCollection NAMEDitem() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.