Back to top

Behave

JS CSS Selector

What is it

A small javascript library to select DOM elements via CSS selectors.

It is inspired by Simon Willison’s selector.js, but uses a totally different design and has a better performance (at least in the tests I did).

It is very small (~250 LOC uncompressed / unpacked).

Alternatives

If size is not a constraint, there are a lot of other libraries that have a very similar feature (and normally a lot more). In most cases you are better off with one of these libraries. Behave’s advantage is just in its small size. Here are a few of the mentioned libraries:

  • jQuery is a feautre-rich and lightweight library which makes heavy usage of CSS selectors.
  • dojo has such CSS selector method (and tons of other features).

Examples

I held a presentation of behave at TNG Technologies. The presentation itself uses behave. The presentation is done for firefox and has not been tested with other browsers. Use the page up and down keys to scroll through the slides.

Download