rsturim
rsturim

Reputation: 6846

What are the implication of having multiple document.ready in a script

I've been asked to help debug a pretty tattered hunk of jQuery. I'm finding the the block contains several occurrences of document.ready -- often different variations of "ready" syntax.

Anyway, besides be horribly disorganized -- is there a code execution impact when several of these events exist on the same page? A negative hit to performance? Or perhaps risk of race conditions or the like?

Upvotes: 1

Views: 104

Answers (3)

Kory Hodgson
Kory Hodgson

Reputation: 790

Each document ready block will be run sequentially as shown here: http://jsfiddle.net/fVM4x/

Also check out the documentation here: http://api.jquery.com/ready/

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114377

They're executed top-to-bottom.

Upvotes: 0

DwB
DwB

Reputation: 38300

each .ready adds a handler to the list of handlers for the "ready" event. There is no race condition; they should be called in the order that they are added.

Upvotes: 1

Related Questions