JavaScript Element tagName Property Tutorial

In this section, we will learn what the Element tagName property is and how to use it in JavaScript.

What is Element tagName Property in JavaScript?

The JavaScript Element tagName property is used to get the name of an HTML tag and return that as a result in uppercase.

Note: there’s another property called nodeName which does the same job, but the difference is that the tagName property is used for element nodes only while the nodeName can also work with attribute-nodes, text-nodes, and comment-nodes.

JavaScript tagName Property Syntax:

element.tagName;

JavaScript tagName Property Input Value

This property is read-only and so we can’t use it to assign a new value.

JavaScript tagName Property Return Value

The return value of this property is a string value that contains the tag name of the target element in uppercase.

Example: using element tagName Property in JavaScript

See the Pen Untitled by Omid Dehghan (@odchan1) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies