What is the difference between $ and $$?

I perform some jQuery functions.

Can someone give me some idea of ​​what is the difference between using $ and $$ ?

+7
source share
8 answers

There is no $$ statement in jQuery documentation. jQuery has a default selector with the $ character. Perhaps this script uses a different javascript library and has some conflicts with jQuery. In this case, you can use jquery.NoConflict to avoid such a problem, and set a different 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 something like avoiding conflicts: var $$ = jquery.noConfict(); , you can use $$ as a jquery selector: $$("#element").method();

For more on documentation, see http://api.jquery.com/jQuery.noConflict/

+5
source

jQuery is an object provided by jQuery. $ is another jQuery alias.

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

Moreover, $$ also provided in the console of modern browsers as the alias document.querySelectorAll . Except that it is overridden by another library. $ also provided in the same way as the alias document.querySelector .

See this answer for more details.

+3
source

Looking at jQuery source code , there is no place where it defines $$ . $$ not part of jQuery, you should confuse it with something else.

+2
source

$ and $$ will work on any web page (if jQuery is also not enabled) in Chrome, FF and Safari, where $ returns the first selector element, here $ is document.querySelector , and $$ returns an array of elements such as document.querySelectorAll . They are built-in functions of Chrome and Firefox browsers, you can see the definition of $ and $$ in safari.

Open Wordpress in any of chrome, firefox or safari and open the developer console to check these results ... (why Wordpress because they won’t use jQuery or Moo tools)

 $('div') returns first div in DOM $$('div') returns all div in DOM 

You can check it here.

+2
source

$ AND $$ is the mootools selector, and $ is also a jquery selector.

see jQuery noconflict-mode

+1
source

Short Anser: $$ NOT defined in jQuery specs, moreover, the designation of a single $( ) sign means that you encapsulate things inside the brackets in a jQuery object.

So the alias $ is an abbreviation to say - I am using the jQuery library, where since double $$ not defined in the jQuery standard library.

+1
source

All jQuery functions are encapsulated in a jQuery object, which is also available as $ . The code you study may use another library (e.g. Mootools) that uses the $$ function.

+1
source

$$ is not significant in jQuery, however it is used as part of the prototype.

$$ prototype

Also verify that this is not a previous version of jquery assigned with noConflict .

Search for the var $$ code to find the possible purpose of the old jquery version.

 var $$ = jquery.noConfict(); 
+1
source

All Articles