tagName property
The tagName property
contains the tag name in upper
case (in capital letters).
Syntax
javascriptelement.tagName;
Example
Let's obtain the #elem element
and output its tag name:
html<div id="elem"></div>javascriptlet elem = document.getElementById('elem');
console.log(elem.tagName);
The code execution result:
javascript'DIV'
Example
Let's output a tag name in lower case. To
do this, use the
toLowerCase
method:
html<div id="elem"></div>javascriptlet elem = document.getElementById('elem');
console.log(elem.tagName.toLowerCase());
The code execution result:
javascript'div'
See also
-
the
outerHTMLproperty
that contains an outer HTML code of an element