Javascript Reference - HTML DOM tagName Property








The tagName property returns the tag name of the element in UPPERCASE.

Browser Support

tagName Yes Yes Yes Yes Yes

Syntax

var v = element.tagName

Return Value

A String type value representing the tag name of the element.





Example

The following code shows how to get the tagName of an element.


<!DOCTYPE html>
<html>
<body>
<p id="demo">test</p>
<!--from w  ww. j a  v a  2  s.c  om-->
<button onclick="myFunction()">test</button>

<script>
function myFunction()
{
    var x=document.getElementById("demo");
    x.innerHTML=x.tagName;
}
</script>

</body>
</html>

The code above is rendered as follows: