From what I understand, adding .first() or :first to a query doesn\'t stop DOM search after the first match. It just tells jQuery to take 1st eleme
As far as I know there's no way to do this in jQuery at the moment. The best you can do is $(selector).first(), where selector is a standard CSS selector not including any Sizzle-specific selectors (so don't use :first). In this case jQuery uses the fast DOM querySelectorAll method in modern browsers.
You can get the optimisation manually by using the DOM querySelector method which is built to select only the first match:
$.getFirst= function(selector) {
if ('querySelector' in document)
return $(document.querySelector(selector));
else
return $(selector).first();
}
however the amount you'll save by doing this is much smaller than the amount you save by making sure querySelectorAll can be used.