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