check if the document is ready js

Solutions on MaxInterview for check if the document is ready js by the best coders in the world

showing results for - "check if the document is ready js"
Henry
19 Aug 2016
1if( document.readyState !== 'loading' ) {
2    console.log( 'document is already ready, just execute code here' );
3    myInitCode();
4} else {
5    document.addEventListener('DOMContentLoaded', function () {
6        console.log( 'document was not ready, place code here' );
7        myInitCode();
8    });
9}
10
11function myInitCode() {}
Ariana
19 Jan 2018
1let stateCheck = setInterval(() => {
2  if (document.readyState === 'complete') {
3    clearInterval(stateCheck);
4    // document ready
5  }
6}, 100);
María Fernanda
07 Sep 2019
1if (document.readyState === 'complete') {
2  // The page is fully loaded
3}