Amar
Amar

Reputation: 363

What is the difference between $ and $$?

I have been going through some jQuery functionality.

Can any one please give me some idea of what the difference is between the use of $ and $$?

Upvotes: 18

Views: 13295

Answers (7)

Felipe Oriani
Felipe Oriani

Reputation: 38608

On jQuery documentation there is no $$ statement. jQuery has a default selector with $ character. Maybe this script uses another javascript package and has some conflicts with jQuery. In this case, you can use jquery.NoConflict to avoid this kind of problem, and set another jquery selector.

Something like:

var s = jQuery.noConflict();

// something with new jQuery selector
s("div p").hide();

// something with another library using $()
$("content").style.display = 'none';

If your code has somethig like to avoid conflicts: var $$ = jquery.noConfict();, you can use $$ as a jquery selector:

$$("#element").method();

See more on the documentation: http://api.jquery.com/jQuery.noConflict/

Upvotes: 8

Ranganadh Paramkusam
Ranganadh Paramkusam

Reputation: 4368

$ and $$ will work on any web page (if jQuery is not included also) on Google Chrome, Firefox and Safari browsers where $ returns first element of selector passed.

Here,

$ is document.querySelector

$$ is document.querySelectorAll

They are native functions of Google Chrome and Firefox browsers, you can see $ and $$ definition in Safari as well.

Open Google in any of Google Chrome, Firefox or Safari, and open Developer Tools to check these results... (why Google, because they won't use jQuery or Moo tools)

$('div');  // returns first DIV in DOM
$$('div'); // returns all DIVs in DOM

enter image description here

Upvotes: 20

Yusubov
Yusubov

Reputation: 5843

Short Anser: $$ is NOT defined in jQuery specifications, in addition the notation of single $( ) - sign means you encapsulate things inside bracket to a jQuery object.

Thus, alias $ is an abbreviation to say - i am using jQuery library, where as double $$ is not defined in a standard jQuery library.

Upvotes: 1

Florian Margaine
Florian Margaine

Reputation: 60747

jQuery is an object provided by jQuery. $ is another, which is just an alias to jQuery.

$$ is not provided by jQuery. It's provided by other libraries, such as Mootools or Prototype.js.

More importantly, $$ is also provided in the console of modern browsers as an alias to document.querySelectorAll. Except if it's overridden by another library. $ is also provided in the same way, as an alias to document.querySelector.

See this answer for more information.

Upvotes: 5

Kevin Bowersox
Kevin Bowersox

Reputation: 94469

$$ has no significant in Jquery, however it is used within the prototype framework.

Prototype $$

Also check that this is not a previous version of Jquery assigned using noConflict.

Search the code for var $$ to find a possible assignment of an older jquery version.

var $$ = jquery.noConfict();

Upvotes: 1

user1726343
user1726343

Reputation:

All jQuery functionality is encapsulated in the jQuery object, which is also accessible as $. The code you are examining might be using a different library (eg. Mootools), that uses a $$ function.

Upvotes: 1

algorhythm
algorhythm

Reputation: 8728

$ AND $$ are mootools selectors and $ is also a jquery selector.

see jquery noconflict-mode

Upvotes: 1

Related Questions