THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM tagName Property

Element Object Reference Element Object

Example

Get the tagName of an element:

var x = document.getElementById("myP").tagName;

The result of x will be:

P
Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The tagName property returns the tag name of the element.

In HTML, the returned value of the tagName property is always in UPPERCASE.

This property is read-only.

Tip: You can also use the nodeName property to return the tag name of an element. The difference is that nodeName also returns attribute nodes, text nodes, comment nodes.


Browser Support

Property
tagName Yes Yes Yes Yes Yes

Syntax

element.tagName

Technical Details

Return Value: A String, representing the tag name of the element in uppercase
DOM Version Core Level 1 Element Object

Examples

More Examples

Example

Using the tagName property together with the event.target property to find out which element triggered a specified event:

var x = event.target.tagName;
Try it yourself »

Related Pages

HTML DOM reference: node.nodeName Property


Element Object Reference Element Object