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.
html
<html>Â Â Â <head>Â Â Â Â Â Â <title>zambiatek</title>Â Â Â Â Â Â <h1 id="d">zambiatek</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> |
Output:
Before Button Click:
After Button Click:
In console the local names of the following elements can be seen.
Supported Browsers:
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 9 and above
- Opera 12.1 and above
- Safari 1 and above
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!




