JavaScript – Tag Name of an HTML Element
To get the tag name of a specific HTML Element as a string, using JavaScript, get reference to this HTML element, and read the tagName
property of this HTML Element.
tagName
is a read only property that returns the tag name of this HTML Element as a string.
Example
In the following example, we will get the tag name of the HTML Element, which is selected by id "myElement"
.
example.html
Try this html file online, and click on the Click Me
button. Tag name of the HTML Element #myElement
will be printed to console, as shown in the following screenshot.
ADVERTISEMENT
Conclusion
In this JavaScript Tutorial, we learned how to get the tag name of an HTML Element in pixels, using JavaScript.