Reputation: 363
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
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
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
Upvotes: 20
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
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
Reputation: 94469
$$ has no significant in Jquery, however it is used within the prototype framework.
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
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
Reputation: 8728
$ AND $$ are mootools selectors and $ is also a jquery selector.
see jquery noconflict-mode
Upvotes: 1