If in a webkit browser like Chrome i do:
$$('span');
I get a result that looks almost exactly the same as jQuery’s:
$('span');
If in the console I look for definition of $$ I get:
bound: function ()
{
return document.querySelectorAll.apply(document, arguments)
}
And for $ I get:
function (a,b){return new c.fn.init(a,b)}
What type of functions can I do on a $$ object that I cannot really do with a jQuery ($) object?
Since
$$is just a wrapper forquerySelectorAll, you can pass any valid selectors.First,
$$isn’t an object like jQuery. It is an object, but it’s just a simple function object that is a wrapper (shortcut) fordocument.querySelectorAll. It returns aNodeListof the elements it found.The only thing it supports that Sizzle doesn’t specifically support, to my knowledge, is
:nth-of-type.(Of course Sizzle defaults to
qsawhen you give a valid selector, so you can passnth-of-typeto the jQuery function in browsers that also supportqsa.)With Sizzle, there are several selectors that are not supported by
querySelectorAll, so you can technically do more with jQuery/Sizzle.Those include:
:eq():gt():lt():first:last:not()(When you give it multiple selectors. Simple:not()values are supported inqsa.):animated:input:button:checkbox:even:odd:has():image:password:radio:reset:selected:submit:text:visible…to name
a fewseveral.Keep in mind that Sizzle first tries to use
querySelectorAll. If you passed a proprietary selector, it then defaults to Sizzle’s own engine.Since
qsais typically faster than Sizzle, it may be advisable to consider alternatives to the proprietary selectors listed above in order to improve performance.Also note that
Webkitdoes not define$$anywhere except for in the console. the$$shortcut is not available in your scripts unless you make it available.