Nut is a concise query selector engine that just allows you to do extremely simple queries.
Oh jeez, another engine?!
Yeah, right, there's a lot of CSS selector engines, but just a few of them are really smalls.
First of all, nut is, most of the time, faster than
Nut is different from the other tiny engines, here's what they are:
- Svetlo (from picoCSS) is also a wrapper around
Quewery handles ids, tags and
querySelectorAllis not supported by all browsers, so supporting it with no fallback is inconsistent
- picoCSS uses
NodeListobjects as arrays, that is inconsistent too (but this framework doesn't seem to be made for cross-browser support, so I don't tell to throw a stone at it)
- QSA, picoCSS and Quewery don't support contexts
Then, nut tries to be fully reliable and as fast as possible by removing the most CSS syntax without becoming unhandy. There's another very interesting engine: micro-selector. It supports another CSS syntax and is extensible.
Here's it can handle:
#foo section .bar p section #foo .bar p div,#foo,.bar div *
And here's it can't:
div#foo div.bar div > p div + p
So, all pseudo-classes, attribute selectors and other advanced syntax are not allowed. But, let's dig in it:
// Return an array nut('#foo');
Of course, queries can have a context (an array, a NodeList, or a node):
// Get nodes from the #foo context nut('.bar p',nut('#foo'));
And that's all you need to know ;)
Nut is compatible with ender and supports some useful syntax.
Selecting nodes, as usually:
$('#foo'); $('.bar p',$('#foo'));
Selecting existing nodes:
var nodes=$('.bar'); $(nodes);
Creating new elements:
// elements var has 2 nodes var elements=$('<b>foo</b><i>bar</i>');
Nut is published under the MIT license.