![Check If the Document is Ready](https://javascriptsource.com/wp-content/uploads/2021/09/Check-If-the-Document-is-Ready-702x526.jpg)
To check if the document is ready and execute some code, you bind an event listener to the DOMContentLoaded
event of the document
object:
document.addEventListener("DOMContentLoaded", handler);
It is somewhat equivalent to the following methods in jQuery:
$(document).ready(handler);
// or
$(handler);
Source
https://www.javascripttutorial.net/dom/events/javascript-document-ready/