Javascript examples for DOM:Element nodeValue
The nodeValue property sets or gets the node value.
For element node, the nodeValue property will return null.
To return the text of an element, return the Text node's node value (element.childNodes[0].nodeValue).
For other node types, the nodeValue property will return different values.
Return the node value:
Set the node value with the following Values
Value | Description |
---|---|
value? | Sets the node value of the specified node |
A String, representing the value of the node.
Possible values:
The following code shows how to get the node value of the first <button> element in the document:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w .jav a2 s .c o m*/ var c = document.getElementsByTagName("BUTTON")[0]; var x = c.childNodes[0].nodeValue; document.getElementById("demo").innerHTML = x; } </script> </body> </html>