Page DOM and Browser loading

suggest change

This is an example to explain the variations of load events.

  1. onload event
<body onload="someFunction()">
<img src="image1" />
<img src="image2" />
</body>

<script>
function someFunction() {
console.log("Hi! I am loaded");
}
</script>

In this case, the message is logged once all the contents of the page including the images and stylesheets(if any) are completely loaded.

  1. DOMContentLoaded event
document.addEventListener("DOMContentLoaded", function(event) {
       console.log("Hello! I am loaded");
   });

In the above code, the message is logged only after the DOM/document is loaded (ie:once the DOM is constructed). 3. Self-invoking anonymous function

(function(){
    console.log("Hi I am an anonymous function! I am loaded");
})();

Here, the message gets logged as soon as the browser interprets the anonymous function. It means, this function can get executed even before the DOM is loaded.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Events:
* Page DOM and Browser loading

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde