tagName property in javascript

tagName property in javascript

tagName property is used to return the tag name of the specified element.

Syntax

var elem = element.tagName;

Example - Getting the tagName 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 in attr variable.
  • Using the tagName property, we are getting the tag name of the specified element and displaying it (alert (attr.tagName)).