Skip to content
Sel is a tiny selector engine that has all of the power of Sizzle in about half the code size.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib fix incorrect var handling Oct 3, 2012
.npmignore test suite working Sep 17, 2011
Cakefile new tests, small change to Array checking Jun 11, 2012
LICENSE initial commit Sep 16, 2011 forgot a period in the Ender examples Apr 22, 2012
package.json fix incorrect var handling Oct 3, 2012

Sel - A small, powerful CSS selector library.

Sel is a CSS selector engine, like Sizzle, which forms the core of jQuery.

Sel uses 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.


Sel supports all of the CSS Level 3 Selectors, as well as the following Draft CSS Level 4 Selectors:

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"]
:with(selector)             /* or :has(selector) */


You can also pass a root context to select from a subset of the document:

sel.sel('div', node); // a DOM node
sel.sel('div', [node1, node2, node3]); // a list of DOM nodes
sel.sel('div', '#foo'); // a selector
sel.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.

Custom pseudo-selectors

Adding a custom pseudo-selector is easy: = function (el, val) {
    return el.nodeName.toLowerCase() === "input" && el.type === "radio";


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. = function (el, val) {
    // val === 'bar'
    return el.getAttribute('foo') === val;


For pseudo-selectors that need to operate on the whole set of currently matched elements, add the batch attribute: = function (els, val, roots) {
    // Do something with all of the elements
    return els.filter(function (el, i) { return (i < val); });
}; = 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 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


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.

You can’t perform that action at this time.