Javascript Reference - HTML DOM nodeValue Property








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.

Browser Support

nodeValue Yes Yes Yes Yes Yes

Syntax

Set the node value.

node.nodeValue=value

Return the node value.

node.nodeValue




Return Value

A String type value representing the value of the node.

Example

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: