The DOM documentElement property is used to return the documentElement as an Element Object. It is a read-only property. It returns a <HTML> Element.
Syntax
document.documentElement Return Value: It returns the documentElement of the document or an element object.
Example: Below program illustrates the documentElement property in HTML.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>
DOM documentElement Property
</title>
<!--Driver Code Ends-->
<script>
function Geeks() {
let x = document.documentElement.nodeName;
document.getElementById("sudo").innerHTML = x;
}
</script>
<!--Driver Code Starts-->
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h2>DOM documentElement Property</h2>
<button onclick="Geeks()">
Submit
</button>
<p id="sudo"></p>
</center>
</body>
</html>
<!--Driver Code Ends-->
- The document.documentElement property returns the root <html> element of the current HTML document, and the code displays its node name (HTML) when the button is clicked.
- Clicking the Submit button executes the Geeks() function, which retrieves the root element's node name using document.documentElement.nodeName and displays it inside the paragraph with the id="sudo".