Javascript Reference - HTML DOM nodeName Property








The nodeName property returns the name of the specified node.

If the node is an element node, the nodeName property has the tagname.

If the node is an attribute node, the nodeName property has the name of the attribute.

Browser Support

nodeName Yes Yes Yes Yes Yes

Syntax

var v = node.nodeName




Return Value

A String type value representing the name of the node.

Example

The following code shows how to get the node name of the body element.


<!DOCTYPE html>
<html>
<body><p id="demo">test</p>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from   w ww. ja  v a 2 s.c  o  m-->
{
    var c = document.body.childNodes;
    for (i=0; i<c.length; i++){
        console.log(c[i].nodeName);
    }
}
</script>

</body>
</html>

The code above is rendered as follows: