I can understand that $()
is jQuery object but what is $
? for example $.fn.each
and $.each
.
I am confused here.
I can understand that $()
is jQuery object but what is $
? for example $.fn.each
and $.each
.
I am confused here.
$
and jQuery
are a function which contains properties.
The jQuery source contains the line
window.jQuery = window.$ = jQuery
This sets $
and jQuery
to refer to the same object (which is a function)
The source also sets properties of this object, like
jQuery.each = function(...) { ... };
This post should explain it, specifically this comment: Note: By default, jQuery uses "$" as a shortcut for "jQuery".
$
is an alias for jQuery
, which is simply a function. When you do $(...)
, you are calling that function. Functions are also objects in JavaScript, so they can have properties -- $.fn
and $.each
are just properties of this object.
In jQuery, the dollar sign $ is simply shorthand for jQuery. Because a $() function is very common in JavaScript libraries, conflicts could arise if more
than one of these libraries is being used in a given page. We can avoid such conflicts by replacing every instance of $ with jQuery in our custom jQuery code.
Extracted text from Learning Jquery .
I think this will be useful to you . :)