Load Events
DOMContentLoaded signals that the initial HTML was parsed. Load waits for more resources, so it is often later than needed.
Where to run this
This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.
A practical example
<p id="message">Waiting</p>
<script>
function ready() { document.getElementById("message").textContent = "DOM is ready"; }
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", ready, {once: true});
else ready();
</script>
What happens
The status changes whether the script starts before or after parsing finishes.