Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <title>Load Event Example</title> </head> <body> <div>You see first triggered event on top of the other.</div> <script> window.addEventListener('load', function() { const newDiv = document.createElement("div"); newDiv.innerHTML = 'loaded event happened!' document.body.append(newDiv); }); window.addEventListener('DOMContentLoaded', function() { const newDiv = document.createElement("div"); newDiv.innerHTML = 'DOMContentLoaded event happened!' document.body.append(newDiv); }); </script> </body> </html>