Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a dollar sign and a dollar sign followed by a period in JQuery?

In jQuery, what is the difference between $ and $.? Please provide a practical explanation if possible.

like image 402
Moshe Avatar asked Jan 05 '11 21:01

Moshe


People also ask

What is '$' in JavaScript?

$ is simply a valid JavaScript identifier. JavaScript allows upper and lower letters, numbers, and $ and _ . The $ was intended to be used for machine-generated variables (such as $0001 ). Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function).

What does dollar sign ($) mean in jQuery?

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s). Basic syntax is: $(selector).action() A $ sign to define/access jQuery. A (selector) to "query (or find)" HTML elements. A jQuery action() to be performed on the element(s)

What does $() mean in jQuery?

In jQuery, the $ sign is just an alias to jQuery() , then an alias for a function. This page reports: Basic syntax is: $(selector).action() A dollar sign to define jQuery. A (selector) to "query (or find)" HTML elements.

What is the dollar sign dot in JavaScript?

The “dollar sign function” $() is typically used to override the lengthy DOM function document. getElementById().


2 Answers

$ is a reference (or synonym, if you want an analogy) to the global jQuery object. $.<method> calls a static method of the jQuery object, where $(<selector>) creates a new instance of the jQuery object.

like image 63
nikc.org Avatar answered Sep 20 '22 21:09

nikc.org


In the context of jQuery, $ refers to the global jQuery object.

$. by itself is invalid JavaScript. As $ is an object, methods on this object are called like on any other object: $.methodname().

Maybe it becomes clearer by substituting $ with jQuery: jQuery.methodname().

like image 38
Felix Kling Avatar answered Sep 20 '22 21:09

Felix Kling