Fast matching of single elements against a pre-compiled selector
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
vendor
.gitignore
LICENSE
README.textile

README.textile

jQuery Selector

Selector tools and reverse mapping for jQuery

  • Parse and examine the AST for a selector
  • Calculate the specifity of a selector
  • Determine if a single element matches a selector ($().is equivilent) much faster that jQuery

Intro

jQuery has an excellent CSS 3 selector engine built in called Sizzle. However, it’s clear focus is on filtering a set of elements down to the set that matches a selector.

jQuery.concrete has a usage pattern quite different from that optimized for by Sizzle. It reuses a small set of selectors (making a more complicated initial parsing step acceptable)
and checks if a single element matches those selectors. In this case, Sizzle can be quite slow.

Usage

Usual usage of jQuery selector:

var sel = $.selector(‘#foo’);
sel.matches(element);

element must be a raw DOM object, not a jQuery element, sequence of elements or anything else

Compatibility

jQuery.selector aims to be 100% compatible with Sizzle (except a couple of corner cases, noted below). Sizzle implements most of the CSS 3 spec plus several extensions.

One set of extensions Sizzle has is a set of pseudo-classes that filter the currently selected set. These pseudo-classes are ‘:first’, ‘:last’, ‘:even’, ‘:odd’, ‘:eq’, ‘:nth’, ‘:lt’, ‘:gt’.
These pseudo-classes are not supported in jQuery.selector, as they don’t make sense when the working set is always a single element.

jQuery.selector currently passes the jQuery selector unit test suite, with the exception of the psuedo-classes mentioned above