The nodeValue
property sets or gets the node value of a node.
To return the text of an element, use element.childNodes[0].nodeValue
since
text in also an node.
nodeValue |
Yes | Yes | Yes | Yes | Yes |
Set the node value.
node.nodeValue=value
Return the node value.
node.nodeValue
A String type value representing the value of the node.
The following code shows how to get the node value of the first button element.
<!DOCTYPE html>
<html>
<body>
<p id="demo">test</p>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from w w w.ja v a 2 s . co m-->
{
var c=document.getElementsByTagName("BUTTON")[0];
var x=document.getElementById("demo");
x.innerHTML=c.childNodes[0].nodeValue;
}
</script>
</body>
</html>
The code above is rendered as follows: