Well, there is one more. From the docs:
There is also $ (document) .bind ("ready", a handler) . This behaves similarly to a ready-made one, with one exception: if a ready-made event is already running, and you try .bind ("ready"), the associated handler will not be executed.
Other initialization methods will always be executed ... so you can find the declaration $(document).ready(function() { //stuff } in several files, for example, and the handler always starts.
I would more often meet with jQuery(document).ready(function($) {}) or $(document).ready(function() {}) ... I think they are more readable.
Another approach would be to call the script immediately before the closing body tag and do something like
(function($) { //stuff })(jQuery);
if you need to avoid conflicts with other libraries with $. This is a standalone anonymous function, and it allows you to use an alias in your field without fear of conflicts from other libraries.
dianovich
source share