Query Plugin

Back to plugins | Download plugin

The Query plugin uses the Sizzle CSS selector engine, the same used in the core of the jQuery library.

Query the DOM

The query() method searches for a group of elements based on a CSS selector. The method accepts 2 arguments in the following order:

  nano.query('#example DIV.test');

The query() method returns an Array of nodes, even if only a single node is found, wrapped in the API. Additionally, the returned Array has 4 methods to access the selected nodes: add(), each(), first() and last().

The add() method allows you to perform another search, adding the nodes found to the initial result. This method accepts the same arguments as the query() method.

  nano.query('DIV > SPAN.message').add('IMG.special');

The each() method allows you to iterate over the nodes found by the query. This method accepts 2 arguments in the following order:

  nano.query('IMG.offer, IMG.special').each(function() { this.style({borderColor: 'green'}); });

Finally, the first() and last() methods return the first or the last node in the Array respectively.

For more information regarding CSS selectors visit the Sizzle Wiki or see CSS3 Selectors.