Possible Duplicate:
Can you have multiple $(document).ready(function() sections?
Is it OK to have multiple calls to $(document).ready on the same page? If so how is the order that the code is run in resolved and does this have any implications
I am using jQuery in my rails app. I have several levels of javascript used through the application, all of which use jQuery.
For example I have some default code that fades out Flash Notices in my application.js
I have a projects.js file that is included in all Project model views, and I have a project/edit.js that is included only in the view rendered by the edit action.
In all three js files I am using:
$(document).ready
{
//Do something
}
It’s fine.
The execution order will be in the same order they were used.
First in First Out
jQuery has an internal queue called
readyListstoring all the callbacks for the ready event. When you call thereadyfunction with a callback is simply add it to the queue and fire the whole queue when the DOM is ready.Looking at the jQuery source code can tell you that easily:
source code: