Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  159] [ 5]  / answers: 1 / hits: 61651  / 13 Years ago, mon, april 18, 2011, 12:00:00

Possible Duplicate:

$(document).ready equivalent without jQuery






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 <body> element, and no jQuery/other libraries.


More From » javascript

 Answers
9

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.


[#92664] Saturday, April 16, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;