Javascript DOM HTML Node nodeName Property for <body> element

Introduction

Get the node name of the <body> element:

var x = document.body.nodeName;

Click the button to get the node name of the body element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {// ww  w .jav a 2  s  . c om
  var x = document.body.nodeName;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related