Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery wait x seconds after document ready

Tags:

jquery

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

like image 505
Email Avatar asked Mar 19 '11 11:03

Email


People also ask

How do I delay the document ready event?

Approach 1: Using the holdReady() method in the jQuery library and the setTimeout() method. First we set the parameter in the holdReady() method to true to hold the execution of the document. ready() method. Then, a timeout function with an appropriate delay time can be added using the setTimeout() method.

Is it possible to hold or delay document ready execution for sometime?

Yes, with jQuery.

How do you make a delay in JavaScript?

The standard way of creating a delay in JavaScript is to use its setTimeout method. For example: console. log("Hello"); setTimeout(() => { console.


1 Answers

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); }); 
like image 173
Alnitak Avatar answered Sep 21 '22 06:09

Alnitak