There are 4 possible readiness values:
- uninitialized - not yet loaded
- Download - Download
- interactive - Loaded enough, and the user can interact with it.
- complete - fully loaded
To see this value, use this code:
document.onreadystatechange = function () { if (document.readyState === YourChoice) {
I could not catch uninitialized
readyState. (but why do I need this?)
If you need a listener to fully load the DOM, use:
document.addEventListener('DOMContentLoaded', YourListener);
or
document.addEventListener('load', YourListener);
or even
window.onload = YourListener;
for jquery:
$(document).on("DOMContentLoaded", function() { });
or
$(document).on("load", function() { });
or
$(window).on("load", function() { });
source share