localName in javascript

localName property in javascript

localName property is used to return the local part of the qualified names (element name).

It returns null if the selected node is not an element.

Syntax

var elem = element.localName;

Example - Getting the localName of an element

Try Yourself

Example Explanation

  • In the above example, when the button is clicked fun_name() function is called.
  • In the Javascript function, first we are getting the element (document.getElementById("idDiv")) and storing it in attr variable.
  • Using the localName property, we are getting the name of the button and displaying it (alert (attr.localName);).