Element tagName Property - Javascript DOM

Javascript examples for DOM:Element tagName

Description

The tagName property returns the element's tag name .

The returned value of the tagName property is always in UPPERCASE.

This property is read-only.

Return Value

A String, representing the tag name of the element in uppercase

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">

<p>paragraph.</p>

<h1>This is a heading</h1>

<button>This is a button</button>

<span>A span element</span>

<p id="demo"></p>

<script>
function myFunction(event) {//ww  w  .  ja  v a 2  s  .com
    var x = event.target;
    document.getElementById("demo").innerHTML = "Triggered by a " + x.tagName + " element";
}
</script>

</body>
</html>

Related Tutorials