Querying the DOM on the Sly

In: web resources

26 Mar 2009

Remember when we thought there may be less CSS selector engines? :) Instead we have renewed performance-based competition among them.

Sly is the latest selector engine created by Harald Kirschner.

To use, it looks like this:

JAVASCRIPT:

  1.  
  2. // Finds all odd rows in all tables
  3. var rows = Sly.search(‘table td:odd’);
  4.  
  5. // Finds all links with class "internal" and an attribute "href" starting with "#".
  6. var links = Sly.search(‘a.internal[href^="#"]‘);
  7.  
  8. // Another notation is also possible, since Sly acts as a constructor
  9. var snippets = Sly(‘pre.highlight.javascript> code’).search();
  10.  
  11. // features is just one element, lists has all list items are siblings of features
  12. var features = Sly.find(‘#features’);
  13. var lists = Sly.search(‘~ ul’, body);
  14.  

What does it feature?

  • Pure and powerful JavaScript matching algorithm for fast and accurate queries
  • Extra optimizations for frequently used selectors and latest browser features
  • Works uniformly in DOM documents, fragments or XML documents
  • Utility methods for matching and filtering of elements
  • Standalone selector parser to produce JavaScript Object representations
  • Customizable pseudo-classes, attribute operators and combinators
  • Just 3 kB! (minified and gzipped, 8 kB without gzip)
  • No dependencies on third-party JS libraries, but developers can override internal methods (like getAttribute) for seamless integration.
  • Code follows the MooTools philosophy, respecting strict standards, throwing no warnings and using meaningful variable names

And it comes with speed tests:

Fork it at GitHub! :)

Comment Form

About this blog

This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.