Javascript DOM HTML Document documentElement Property

Introduction

The documentElement property returns the documentElement of the document, as an Element object.

The following code returns the documentElement of the document, as a node name:

var x = document.documentElement.nodeName;

Click the button to display the node name of the documentElement.

View in separate window

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

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

<script>
function myFunction() {//w ww .  j a v a2  s. co m
  var x = document.documentElement.nodeName;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

For HTML documents the returned object is the <html> element.

This property is read-only.

The document.body element returns the <body> element.

The document.documentElement returns the <html> element.




PreviousNext

Related