Get the node value of the first <button> element in the document:
var x = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
Click the button get the node value of the first button element in the document.
Text inside elements are considered to be text nodes.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j av a 2 s. c o m var c = document.getElementsByTagName("BUTTON")[0]; var x = c.childNodes[0].nodeValue; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The nodeValue property sets or gets the node value of the specified node.
If the node is an element node, the nodeValue property will return null.
Possible values: