JavaScript element.tagName Property
You are Here:
JavaScript element.tagName Property
The element.tagName
property returns the name of the tag for the given element.
Note: This property is read-only.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p id="whatTag">Click on the button to display the tagName of this element.</p>
<button onclick="myFunction()">Click Me</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var elem = document.getElementById("whatTag");
function myFunction(){
x.innerHTML = "TagName = " +elem.tagName;
}
</script>
</body>
</html>
Syntax
element.tagName
Return Values
Value | Explanation |
---|---|
String | Returns the name of the tag for the given element. |
More Examples
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">
<h2>Click Me (h2)</h2>
<div>Click Me (div).</div>
<p>Click Me (p).</p>
<button>Click Me (button)</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
function myFunction(e){
x.innerHTML = "You Clicked = " +e.target.tagName;
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.