Document documentElement Property - Javascript DOM

Javascript examples for DOM:Document documentElement

Description

The documentElement property returns the <html> element, as an Element object.

This property is read-only.

document.body element returns the <body> element, while the document.documentElement returns the <html> element.

Return Value

The document's documentElement, as an Element object

The following code shows how to return the documentElement of the document, as a node name:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">display the node name of the documentElement</button>

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

<script>
function myFunction() {//from ww w  .  j  a va2s  .  c  o  m
    var x = document.documentElement.nodeName;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials