Check If the Document is Ready

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);Code language: JavaScript (javascript)

It is somewhat equivalent to the following methods in jQuery:

$(document).ready(handler);
// or
$(handler);Code language: JavaScript (javascript)

Was this tutorial helpful ?