Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is $$ and $x in Chrome Javascript console?

I saw Chrome's autocomplete suggestions when I was testing JQuery and saw $$ and $x are defined. What are they and where did they come from? I saw What is the variable $x used for in Chrome?, but what is $$?

> $
  function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    } jquery.js?body=1:62
> $$
  function $$() { [Command Line API] }
> $x
  function $x() { [Command Line API] }

This is something ogooglebar.

like image 958
Chloe Avatar asked Jan 05 '14 05:01

Chloe


2 Answers

$$(selector):

Returns an array of elements that match the given CSS selector. This command is equivalent to calling document.querySelectorAll().

like image 175
CD.. Avatar answered Sep 18 '22 23:09

CD..


I had this same question. From the link Ast Derek posted, it looks like the following objects exist by default:

$() is an alias for document.querySelector()
$$() is an alias for document.querySelectorAll()

I've checked both Chrome and Firefox, and these seem to be true for both.

When you link jQuery, $() gets replaced by the jQuery object, but $$() still exists with its default behavior. Pretty confusing for someone who is new to all of this stuff.

like image 20
Niko Bellic Avatar answered Sep 17 '22 23:09

Niko Bellic