0

I have written a basic Hello World application using jQuery in an HTML page in eclipse.

 <!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script>
<script type="text/javascript" >
    window.onload = function (){
        alert("Window loaded");
    }

    $(document).ready(function(){
        alert("DOM loaded");
    })
</script>
</head>
<body>
    <p>Hello </p>
</body>
</html>`

I have used JRE 8 in eclipse. Upon running it on Chrome, "Window loaded" alert box displays first and then "DOM loaded". Ideally it should be opposite. DOM should load first. DOM loads first if refernece jQuery library from google APIs.

Could anybody help me on this? The question is not about the comparison between the two.

kumarras
  • 116
  • 5
  • You may want to leave out the jQuery dependency to test these things. Also, a duplicate: https://stackoverflow.com/questions/3698200/window-onload-vs-document-ready – Bram Vanroy Apr 22 '18 at 17:22
  • 4
    Possible duplicate of [window.onload vs $(document).ready()](https://stackoverflow.com/questions/3698200/window-onload-vs-document-ready) – Bram Vanroy Apr 22 '18 at 17:23
  • @BramVanroy I know the difference but why window is loading before DOM when I am referencing the jQuery lib from local. DOM loads first when I give the src from google APIs. – kumarras Apr 22 '18 at 18:07

0 Answers0