11

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.

2

3 Answers 3

10

$$(selector):

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

7

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.

1
2

There is also $x() function for those who want to use xpath

e.g.

$x("//div")

for xpath syntax see : https://devhints.io/xpath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.