Adola
Adola

Reputation: 588

Calling function AFTER .ready() in Javascript

Is there a way to call a JavaScript function after the .ready() function has executed?

I think there's something funny going on in some DOM structuring in my code, and I want to try calling jquery.('reload') on a section. But I need to call it AFTER the $(document).ready(function(){}) is called.

To clarify a bit more, I'm using jQuery's masonry, and I'm having an issue with the rendering of elements. It comes with a method 'reload', and when called inside of .ready(), doesn't render correctly, but if done on say, a scroll event, it works fine.

Upvotes: 0

Views: 1773

Answers (3)

user2428118
user2428118

Reputation: 8104

If you want your code to be executed right after .ready() is executed, you can use a setTimeout of 0 milliseconds.

$.ready(function(){

    setTimeout(myCoolFunction,0);
});

This example will execute myCoolFunction as soon as possible after .ready() has occurrred.

Upvotes: 1

Bruno Schäpper
Bruno Schäpper

Reputation: 1302

You could try the .load() method. It's fired when every resource is loaded. .ready() is as soon as the DOM is fully loaded.

EDIT: Just noticed, the .load() shorthand is deprecated, use $().bind("load", fn) instead

Upvotes: 0

Prince
Prince

Reputation: 199

What does it mean jquery.('reload')?? Maybe you can call it last in the $(document).ready(function(){})!

Upvotes: 0

Related Questions