3

I can understand that $() is jQuery object but what is $? for example $.fn.each and $.each.

I am confused here.

Sampson
  • 265,109
  • 74
  • 539
  • 565
Aditya Shukla
  • 13,595
  • 12
  • 38
  • 36
  • 1
    possible duplicate of [What is the $ in jQuery?](http://stackoverflow.com/questions/1049112/what-is-the-in-jquery) – JasCav Feb 11 '11 at 17:59
  • Try to keep in mind, too, that all functions are objects in JavaScript. $ is the jQuery object which is also a function, and $() calls that function. – treeface Feb 11 '11 at 18:04

4 Answers4

6

$ 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(...) { ... };
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
2

This post should explain it, specifically this comment: Note: By default, jQuery uses "$" as a shortcut for "jQuery".

Community
  • 1
  • 1
SquidScareMe
  • 3,108
  • 2
  • 24
  • 37
1

$ 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.

casablanca
  • 69,683
  • 7
  • 133
  • 150
0

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 . :)

Andrew Collins
  • 2,541
  • 3
  • 17
  • 16