Possible Duplicate:
JQuery - multiple $(document).ready … ?
What are the implications of having multiple javascript files, each with its own $(document).ready function?
Possible Duplicate:
JQuery - multiple $(document).ready … ?
What are the implications of having multiple javascript files, each with its own $(document).ready function?
When having multiple things bind with the $(document).ready();
, the events will be hit in the order that they were bound. There are no real negative repercussions with this, but keep in mind that any variables defined in one of these methods loses scope, and won't be available in the other events.
To get around the javascript scoping issues, just define cross-ready-event variables outside of the $(document).ready();
blocks.
All functions will be executed in the order they were bound. See the jQuery documentation:
When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.
So all functions are executed and you can influence the order in which they are executed. However, I would strongly advice against basing any logic in the execution order as this may proof pretty brittle.
nothing. They all will attach a lister to be executed when the document is ready. Only implication afaik is that they will be executed in the order they were attached.
All that function does is add an event handler to the onload event for the document, so by doing that you are simply making Javascript execute more than one thing upon finishing loading the page.
There are no downsides to it performance wise. However, if you're having all of that stuff happen upon pageload, you might want to have one init.js file (or something similar) that calls all of the other functions upon pageload. This way it's all in one place and easier to manage.
However, besdies readability and management, it's perfectly fine.