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/