Small, fast CSS4 selector library
Sel is a CSS selector engine, like Sizzle, which forms the core of jQuery.
querySelectorAll when it's available, but will fallback on the custom engine when qSA fails.
Sel is written in CoffeeScript with an emphasis on making the code clear and easy to understand.
/* subject overriding *////* id references */[/* case insensitive attribute matching */) /* :nth-match and :nth-last-match */) /* :local-link */) /* :column */) /* :nth-column and :nth-last-column */
Sel also supports the following extensions:
[)) /* or :has(selector) */)
You can also pass a root context to select from a subset of the document:
selsel'div' node; // a DOM nodeselsel'div' node1 node2 node3; // a list of DOM nodesselsel'div' '#foo'; // a selectorselsel'div' selsel'div'; // previous result set
Unlike Sizzle, which only supports using a single root node, Sel can use any number of nodes as roots for the query.
Adding a custom pseudo-selector is easy:
return elnodeNametoLowerCase === "input" && eltype === "radio";;selsel'input:radio';
The function is passed the current element and, optionally, the value that was passed to the pseudo-selector. It
true if the element matches the pseudo-selector and
// val === 'bar'return elgetAttribute'foo' === val;;selsel'div:foo(bar)';
For pseudo-selectors that need to operate on the whole set of currently matched elements, add the
// Do something with all of the elementsreturn elsfilter return i < val; ;;selpseudosbarbatch = true
It's easy to use Sel with Ender:
$ ender build sel [module, ...]
When using Sel with Ender, there are some convenient methods you can take advantage of:
$'.parent'find'.child' // Same as $('.parent .child') or $('.child', '.parent')$'.foo'union'.bar' // Same as $('.foo, .bar')$'.baz'difference'.bat' // Same as $('.baz:not(.bat)')$'.qux'intersection'.thud' // Same as $('.qux.thud')
You can also use the synonyms
Sel (with the es5-basic module) supports the following browsers
CoffeeScript and NPM are required to build the test suite. Since the tests employ iframes, they cannot be run directly from disk.
This library was inspired by Qwery.