$ vs. jQuery: What should I use?

What is the difference between the two? What's better?

+7
source share
3 answers

$ is an alias for jQuery , none of them are "better", jQuery provided if something else using $ , like Prototype (or jQuery.noConflict() , was called for another reason ...).

I prefer $ for short, because I know that this applies to jQuery if you are not sure (e.g. when writing a plugin) use jQuery for your main link, for example:

 (function($) { //inside here $ means jQuery })(jQuery); 
+15
source

Functionality is identical if there is no conflict.

Use 'jQuery' instead of '$' to be especially explicit / descriptive, or if you are currently using or suggest using another library that defines '$'.

See also http://api.jquery.com/jQuery.noConflict/

+1
source

jQuery == $ == window.jQuery == window.$

jQuery and $ are defined in the window, and $ can be used if no other library uses it, creating conflicts.

Use either jQuery.noConflict() or closure:

 (function ($) { // code with $ here })(jQuery) 
+1
source

All Articles