Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Use DOMContentLoaded to make sure the DOM is ready and loaded

- The `DOMContentLoaded` event can be used to make sure the DOM is loaded. - Note that external resources like images may not be loaded at that point. - via: https://javascript.info/onload-ondomcontentloaded

Example:

Code

function kickoff() {
    console.log("kickoff")
}
        
document.addEventListener("DOMContentLoaded", kickoff);

You can also do it with an anonymous funciton:

Code

document.addEventListener("DOMContentLoaded", () => {
    console.log("DOMContentLoaded")
});