Slat.js Logo

I made a tiny dom selector library called Salt.js.

It uses a regular expression to map different queries you pass through it to their native get functions. The reason I don’t just use querSelectorAll for everything is because it is slower than the native get commands*. See this jsperf test.

Yes, I see that the mapping is slower for newer versions of Chrome. But, almost every other browser and device is slower using querySelectorAll over the mapping method. Also keep in mind the regex used in that example is much more complicated than mine.

Here are some examples of how you would use the library:

Salt.js Examples

// get by id
// get by class name
// get by element name
// get by element tag name
// get element using querySelectorAll
$('*div div.inside');
// getAttribute of name
// getAttribute of name from nodelist

Check out the library on Github.


Looks like there are a bunch of better ways to make this smaller! I’ve updated the github to reflect the new libraries. I have also added a jsPerf test.