Run code before the DOM is fully loaded - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Description

Run code before the DOM is fully loaded

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <style type="text/css">

.foobar { background-color: #CCC; }


      </style> 
   </head> 
   <body> 
      <script type="text/javascript">
        window.document.body.className = "foobar";
    /*  w w  w  .j  a  v  a 2 s.c  om*/
      </script> 
      <div style="border: solid 1px">
         <br>
      </div> 
      <script type="text/javascript">
        console.log("happens before DOM is fully loaded");
        console.log(window.document.body.className);
    
      </script> 
      <span>Appears after the console.log() call.</span>  
   </body>
</html>

Related Tutorials