How to work with document.documentElement in JavaScript?

HTMLJavascriptProgramming Scripts

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

Live Demo
<!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>
raja
Published on 26-Feb-2018 14:43:45
Advertisements