I'm a little confused about all the different ways to create a new jQuery object.
the relevent docs seem to be: http://api.jquery.com/ready/ http://api.jquery.com/jQuery/
From those two docs the following are all equivalent, (with the exception of aliasing or not aliasing '$'):
Is that correct? Did I miss any?
These are somewhat equivalent:
$(document).ready(handler) - tuns the handler when the DOM is loaded$().ready(handler) - runs the handler when the DOM is loaded (deprecated, don't use)$(handler) - runs the handler then the DOM is loaded - shortcut to $(document).ready(handler)
jQuery(function($) {}) same as #3 above, just using jQuery instead of the $ aliasjQuery(document).ready(function($) {}) - same as the first, again using jQuery instead of the $ aliasIf $ is defined as something else, e.g. Prototype, then the first 3 won't work. The last 2 are similiar they're just accepting the first argument passed in (the jQuery object) and making it $ inside, making it possible to do this even when $ is something else:
jQuery(function($) {
$("input").val("something");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With