Recently, I read about the effectiveness of various selector engines. I know that jQuery uses the Sizzle engine and this blog post about some jQuery materials that mentioned that the Sizzle engine breaks your selector into an array, then parses it from left to right.
Then, from right to left, it begins to decrypt each element using regular expressions. It also means that the right side of your selector should be as specific as possible - for example, the name of an identifier or tag.
My question is: is it more efficient to start the selector with just the given id or tag name:
var div = $('#someId'); //OR var div = $('div#someId');
Since I write my CSS in the form of div#someId , I usually do my selectors the same way, can I get Sizzle to do the extra work (if QuerySelectorAll is not available)?
performance javascript jquery sizzle
Chad Aug 31 '11 at 19:08 2011-08-31 19:08
source share