48

following code waits till dom ready

jQuery(document).ready(function(){

what do i have to write to simple let the execution of the jquery function wait for 2 seconds after the document is ready?

i need this to narrow down a conflict between multiple instances of a plugin.

THX

Email
  • 2,395
  • 3
  • 35
  • 63
  • usually who is asking your question have errors in calling functions depend on another functions inside document.ready, if this is your problem try http://stackoverflow.com/questions/3008696/after-all-document-ready-have-run-is-there-and-event-for-that – Mhmd May 12 '13 at 17:58

4 Answers4

98

Wrap your existing function with a call to setTimeout, ie, replace your current:

jQuery(document).ready(function() {
     ....
});

with

jQuery(document).ready(function() {
    setTimeout(function() {
         ....
    }, 2000);
});
Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • It would be cool if there was something like this that did the same thing but said "Loading..." (spins around) and waits till the "document" is really, **really** ready ;-) – PJ Brunet Jul 12 '12 at 03:21
3

You can use

$(window).load(function(){}); 

instead of

$(document).ready(function(){});

I took reference from jquery forum

Always_a_learner
  • 4,585
  • 13
  • 63
  • 112
2

By using window.setTimeout.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
2

Read about setTimeOut(). http://www.w3schools.com/jsref/met_win_settimeout.asp

Rael Max
  • 393
  • 2
  • 6