0

Possible Duplicate:
What is the $ in jQuery?

We know that $ is an alias of jQuery, while using jQuery javascript framework.

But internally what $ is ?

I mean whether it is an object, function or other thing?

Community
  • 1
  • 1
Jatin Dhoot
  • 4,223
  • 8
  • 37
  • 58

5 Answers5

2

$ is a function object in jQuery. It can take a number of different types of parameters or methods. That's why you will see things like:

$("#content")

In that use, it's just a function - identical to:

jQuery("#content")

In this example, it returns an object that contains both the collection of DOM items matching the passed in CSS string and has a whole bunch of methods that let you operate on that collection of items it returned such as:

var html = $("#content").html()

to get the innerHTML of that DOM object.

It is usually used like a function $(params), but can also has methods as an object $.get().

But, most of all $ is just a symbol for a function object that also has methods. It could be called foo or anything else so it's not anything unusual in Javascript.

jfriend00
  • 637,040
  • 88
  • 896
  • 906
  • Not *just* a function. E.g. you can do `$.get('myhtmlpage.html', myCallBack);` which would not be possible unless `$` were also an object. See @Steffen's answer. – LarsH Jul 15 '11 at 07:46
  • Since all functions are also objects in JS, I called it a function. In any case, I've enhanced my choice of wording. – jfriend00 Jul 15 '11 at 07:50
2

$ is just and alias. Its same as jQuery Object. That is its reference to jQuery Object.

sushil bharwani
  • 28,837
  • 30
  • 92
  • 126
1

$ is an object, just like jQuery is. Besides, all objects in javascript are functions and all functions are objects.

Steffen Müller
  • 2,220
  • 13
  • 18
0

$ is a variable in exactly the same way that jQuery is a variable. And its value is a function.

Peter
  • 121,125
  • 53
  • 174
  • 208
0

It's just a pointer to the JQuery prototype function.

AlienWebguy
  • 75,484
  • 17
  • 116
  • 141