HTML DOM localName property

The HTML DOM localName property returns the local name of an element. This is a read only property.

Syntax:

element.localName

Return Value: A String representing the local Name of the element.

Example:

The following example shows how to get localName of an element using this property.



filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
   <head>
      <title>GeeksforGeeks</title>
      <h1 id="d">GeeksforGeeks</h1>
      <button id="btn">Click Here</button>
      <script>
          const element = document.getElementById("btn");
          const di=document.getElementById("d");
    element.addEventListener("click", function() {
  console.log(di.localName);
  console.log(element.localName);
});
      </script>
   </head>
</html>

chevron_right


Output:

Before Button Click:

After Button Click:

In console the local names of the following elements can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

full-stack-img

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 :


Be the First to upvote.


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