Definition and Usage nodeName ..
The nodeName property returns the name of the specified node.
If the node is an element node, the nodeName property will return the tag name.
If the node is an attribute node, the nodeName property will return the name of the attribute.
For other node types, the nodeName property will return different names for different node types.
Tip: You can also use the tagName property to return the tag name of an element. The difference is that tagName only return tag names, while nodeName returns the name of all nodes (tags, attributes, text, comments).
This property is read-only.
Return Value: A String, representing the name of the node.
Possible values:
Returns the tagname for element nodes, in uppercase
Returns the name of the attribute for attribute nodes
Returns "#text" for text nodes
Returns "#comment" for comment nodes
Returns "#document" for document nodes
Syntax : node.nodeName
Differents way how to declare nodeName Property in program.
CODING:The nodeName property returns the name of the specified node.
If the node is an element node, the nodeName property will return the tag name.
If the node is an attribute node, the nodeName property will return the name of the attribute.
For other node types, the nodeName property will return different names for different node types.
Tip: You can also use the tagName property to return the tag name of an element. The difference is that tagName only return tag names, while nodeName returns the name of all nodes (tags, attributes, text, comments).
This property is read-only.
Return Value: A String, representing the name of the node.
Possible values:
Returns the tagname for element nodes, in uppercase
Returns the name of the attribute for attribute nodes
Returns "#text" for text nodes
Returns "#comment" for comment nodes
Returns "#document" for document nodes
Syntax : node.nodeName
Differents way how to declare nodeName Property in program.
<!DOCTYPE html>
<html>
<body><!-- comment node -->
<h4>nodeName nodeType</h4>
<p>Click the button get the node name, node type and node value in body tag of all chid node</p>
<button onclick="info()">View</button>
<p id="p"></p>
<script>
function info() {
var c = document.body.childNodes;//also declare dedocument.body.children;
var info="";
for (var i = 0; i < c.length; i++) {
info += "The node name: " + c[i].nodeName + "<br>";
info += "The node type: " + c[i].nodeType+ "<br>";
}
document.getElementById("p").innerHTML = info + c.length + " Tag in body.";
}
</script>
</body>
</html>
<html>
<body><!-- comment node -->
<h4>nodeName nodeType</h4>
<p>Click the button get the node name, node type and node value in body tag of all chid node</p>
<button onclick="info()">View</button>
<p id="p"></p>
<script>
function info() {
var c = document.body.childNodes;//also declare dedocument.body.children;
var info="";
for (var i = 0; i < c.length; i++) {
info += "The node name: " + c[i].nodeName + "<br>";
info += "The node type: " + c[i].nodeType+ "<br>";
}
document.getElementById("p").innerHTML = info + c.length + " Tag in body.";
}
</script>
</body>
</html>
Comments
Post a Comment