Implementation of CSS3 selectors in JavaScript
Two years ago there was a need for an implementation of CSS3 selectors in JavaScript (as a part of a debugging tool I was working on). The implementation is ready and tested, but is not needed anymore so I’ve decided to publish it for free download.
The implementation is almost 100% complete. It can even handle such things as unicode notations. For example, the following selector is processed exactly as per the spec:
:not(:root):not(form):first-child:not(:lang(en)) > div:first-child ~ div
The library uses standard DOM methods only, which means that there isn’t any pre-conversion of the CSS selector to an XPath expression as other such libraries usualy do. The script hasn’t been much optimized in term of speed and doesn’t work in IE. The main and only goal was to create an implementation that will follow the specification as much as possible and work in the Gecko family browsers.
Download: Selectors.js (licence Creative Commons Attribution 3.0 Unported).
HTML version with syntax highlighting.
You can try the library directly from your browser (unless you are using IE) on a demo page.
An application to the official W3C’s CSS3 selectors test suit is also available. Note that when performing those tests all !important statements are being ignored.
Similar posts:
Tags: css, javascript, webdev

Entries