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?
$$
is, as you said, webkit-specific and should only really be used in console. It has very similar selectors to jQuery, the difference being that it will return an array of DOM Nodes whereas jQuery will return a jQuery array
These two are identical:
$$('span');
$('span').get();
jQuery selectors are actually a bit more powerful since they add selectors that don't exist in the dom like :checkbox
, :contains
, etc.
Reference: JQuery Selectors
WebKit defines $$
and $
by default as shorthand references to the document.querySelectorAll
. When jQuery loads, it replaces the value of $
with the jQuery function. jQuery also preserves the original $
value if you need it. WebKit does this to introduce a consistent API for querying the DOM, regardless of whether you are using jQuery or not.
The big difference is that the result of querySelectorAll
is an array of DOM elements (a NodeList - thanks @lonesomeday), whereas jQuery's is the jQuery object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With