In JavaScript, when I want to run a script once when the page has loaded, should I use window.onload or just write the script? Here, we are using the window.onload () to change the background color, width, and height of the div element after loading the web page. Manage Settings By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Time arrow with "current position" evolving with overlay number. Naturally, it has to wait for styles to load. The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. How to check whether the background image is loaded or not using JavaScript ? To learn more, see our tips on writing great answers. These two properties are mutated due to legacy conformance. If necessary, use a