div! .box /* subject overriding */label /for/ input /* id references */[attr = "val" i] /* case insensitive attribute matching */div:nth-match(3 of .box) /* :nth-match and :nth-last-match */a:local-link(0) /* :local-link */td:column(col.profit) /* :column */td:nth-column(even) /* :nth-column and :nth-last-column */
Sel also supports the following extensions:
[attr != "val"]:contains(text):with(selector) /* or :has(selector) */:without(selector)
Roots
You can also pass a root context to select from a subset of the document:
sel.sel('div', node); // a DOM nodesel.sel('div', [node1, node2, node3]); // a list of DOM nodessel.sel('div', '#foo'); // a selectorsel.sel('div', sel.sel('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.
The function is passed the current element and, optionally, the value that was passed to the pseudo-selector. It
should return true if the element matches the pseudo-selector and false otherwise.
sel.pseudos.foo = function (el, val) { // val === 'bar' return el.getAttribute('foo') === val;};sel.sel('div:foo(bar)');
For pseudo-selectors that need to operate on the whole set of currently matched elements, add the batch attribute:
sel.pseudos.bar = function (els, val, roots) { // Do something with all of the elements return els.filter(function (el, i) { return (i < val); });};sel.pseudos.bar.batch = true
Ender
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 and and not, for union and difference, respectively.
Browser Support
Sel (with the es5-basic module) supports the following browsers
IE 6-10
Chrome 1-12
Safari 3-5
Firefox 2-5
Opera
Tests
CoffeeScript and NPM are required to build the test suite. Since the tests employ iframes, they cannot be run directly from disk.