Definition and Usage nodeValue..
The nodeValue property sets or returns the node value of the specified node.
If the node is an element node, the nodeValue property will return null.
Note: If you want to return the text of an element, remember that text is always inside a Text node, and you will have to return the Text node's node value (element.childNodes[0].nodeValue).
For other node types, the nodeValue property will return different values for different node types.
Return Value: A String, representing the value of the node.
Possible values:
Returns null for element nodes and document nodes
Returns the value of the attribute for attribute nodes
Returns the content for text nodes
Returns the content for comment nodes
Syntax :
Return the node value: node.nodeValue
Set the node value: node.nodeValue = value
Differents way how to declare nodeValue Property in program.
CODING:The nodeValue property sets or returns the node value of the specified node.
If the node is an element node, the nodeValue property will return null.
Note: If you want to return the text of an element, remember that text is always inside a Text node, and you will have to return the Text node's node value (element.childNodes[0].nodeValue).
For other node types, the nodeValue property will return different values for different node types.
Return Value: A String, representing the value of the node.
Possible values:
Returns null for element nodes and document nodes
Returns the value of the attribute for attribute nodes
Returns the content for text nodes
Returns the content for comment nodes
Syntax :
Return the node value: node.nodeValue
Set the node value: node.nodeValue = value
Differents way how to declare nodeValue Property in program.
<!DOCTYPE html>
<html>
<body>
<p><strong>Note:</strong> Text inside elements are considered to be text nodes, so we return the node value of the button element's first child (childNodes[0]).</p>
<p id="demo"></p>
<button onclick="myFunction()">Click ME!</button>
<script>
function myFunction() {
var c = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
document.getElementById("demo").innerHTML = c;
}
</script>
</body>
</html>
<html>
<body>
<p><strong>Note:</strong> Text inside elements are considered to be text nodes, so we return the node value of the button element's first child (childNodes[0]).</p>
<p id="demo"></p>
<button onclick="myFunction()">Click ME!</button>
<script>
function myFunction() {
var c = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
document.getElementById("demo").innerHTML = c;
}
</script>
</body>
</html>
Comments
Post a Comment