The DOM tagName Property is used to return the tagname of the Element. It is read-only property and used to display the returned value of tagName in UPPERCASE letters.Â
Syntax
element.tagName Return Value: It returns a string value which represent the tagName of the element in UPPERCASE letters.Â
Example:Â
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM tagName Property</title>
<style>
h1 {
color: green;
font-size: 35px;
}
</style>
</head>
<body>
<center>
<h1>GeeksForGeeks</h1>
<!--Driver Code Ends-->
<h2 id="GFG">DOM tagName Property</h2>
<button onclick="Geeks()">Submit</button>
<p id="sudo"></p>
</center>
<script>
function Geeks() {
var w = document.getElementById("GFG").tagName;
document.getElementById("sudo").textContent = w;
}
</script>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
- In HTML documents it always returns the tag name in uppercase (e.g., a <div> returns "DIV"). In XML/XHTML documents it preserves the original case from the markup. This is different from localName, which returns the lowercase form in HTML.
- For Element nodes, tagName is identical to nodeName. It returns the qualified name of the element (including any namespace prefix if present), making it a quick way to identify the element type without needing extra methods.