Tuesday, November 6, 2018

javascript - Is there a way to check document.ready() if jQuery is not available?










I know you can use the window.onload event to make functions run, but is there a way for a script to query if the document is ready or not?



Something like



function update()
{
if( !document.ready() ) // don't do unless document loaded
return ;
}
window.setInterval( 'update();', 100 ) ;


Cannot change the element, and no jQuery/other libraries.


Answer



Here you go:



var tid = setInterval( function () {
if ( document.readyState !== 'complete' ) return;
clearInterval( tid );
// do your work
}, 100 );


Read about the document.readyState property here. I am not sure if all current browsers implement it.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...