Projects | Contribute in GitHub


@version    0.1.1
@date       2015-05-10
@stability  2 - Unstable

Selector lite – Build Coverage

A small pure-JavaScript CSS selector engine.


var selector = require("selector-lite")

// Can be used to implement browser built-in functions.

function getElementById(id) {
    return selector.find(this, "#" + id, true)
function getElementsByTagName(tag) {
    return selector.find(this, tag)
function getElementsByClassName(sel) {
    return selector.find(this, "." + sel.replace(/\s+/g, "."))
function querySelector(sel) {
    return selector.find(this, sel, true)
function querySelectorAll(sel) {
    return selector.find(this, sel)


Custom selectors

Custom selector can be added to selector.selectorMap, where method shortcuts are available (m->matches, c->closest, n->next, p->prev).

// Add `:input` selector
selector.selectorMap.input = "_.tagName=='INPUT'"

// Add `:val()` selector
selector.selectorMap.val = "_.value==v"

Coding Style Guidelines


Copyright (c) 2015 Lauri Rooden <[email protected]>
The MIT License

Tags: browser, css, selector, matches, closest, litejs

Have an update or suggestion for this note? You can edit it and send me a pull request.

Fork me on GitHub

Since 2013 to 2015