HTML - DOM Document documentElement Property



The documentElement property is used to return the documentElement as an Element Object.The document element is the root element of the document which in case of an HTML document will be the HTML element.It is a read-only property.

Syntax

document.documentElement;

Return Value

It returns an element object or the documentElement of the document.

Example of HTML DOM Document 'documentElement' Property

The following example illustrates use of documentElement property.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM documentElement Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p id="docele"></p>
    <script>
        function fun() {
            let x = document.documentElement.nodeName;
            document.getElementById("docele").innerHTML =
                "The document element for this document is: " + x;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
documentElement Yes 1 Yes 12 Yes 1 Yes 1 Yes 7
html_dom.htm
Advertisements