Computer >> Computer tutorials >  >> Programming >> Javascript

How to work with document.documentElement in JavaScript?


Use the document.documentElement property in JavaScript to get the documentElement of the document i.e. the nodeName. You can try to run the following code to implement document.documentElement property in JavaScript −

Example

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   
   <body>
      <p>Demo Text</p>
      
      <script>
         document.body.style.backgroundColor = "gray";
         var a = document.documentElement.nodeName;
         document.write("Node Name: "+a);
      </script>
      
   </body>
</html>