JavaScript tagName

It returns the name of the element.

Consider below example,

<script type="text/javascript">
function gettagname()
{
var name_element = document.getElementById('txt_name');
alert("I am a " + name_element.tagName + " element")
}
</script>

<input type="text" name="name" id="txt_name" value="learn web development">
<input type="button" value="Get Tag name" onClick="gettagname();">

When you click button ‘Get Tag name’ it just showing I am a INPUT element with alert box.

Display:



Posted in Javascript