Lose the jQuery Bloat ­— DOM Manipulation with NodeList.js

This is the editorial from the latest JavaScript newsletter. You can subscribe here.

There has been somewhat of a backlash against jQuery as of late, with many people keen to point out that you might not actually need it and some even going as far as to declare it harmful. Whether that’s true or not is quite a contentious subject and one which quickly divides opinion. Personally, I’m a huge jQuery fan (as is my co-editor Aurelio) and I use it unashamedly in all of my projects.

Yet on those occasions when I’ve been feeling bold and have started a project in plain JS, it doesn’t take long before I find myself writing something like:

[].forEach.call(document.querySelectorAll('div'), function(div) {
    div.style.color = "red";
});

At which point I usually think “fuhgeddaboudit!” and go back to including jQuery.

So why am I even mentioning this? Well, a little while back I ran across a tiny library called NodeList.js. This library makes manipulating the DOM with the browser’s native APIs as easy as it is with jQuery, but for a fraction of the size.

Using NodeList.js, the above snippet could be rewritten as:

$$('div').style.set('background', 'red');

which is much saner/more readable than its plain JS equivalent.

And this got me thinking. The author of this library (a guy named Edwin) had obviously had the same frustration as me, but, in contrast to my lazy self, had got off his backside and done something about it.

As my colleague Louis has previously mentioned, one thing we’d like to see more of at SitePoint is developers writing articles about the tools they’ve built, so I invited Edwin to introduce his library and demonstrate which problems it solves. I think you’ll agree, he did a pretty good job.

And now it’s over to you. Would you consider giving Edwin’s library a test drive? Would you like to ask him how he made it? Maybe you even have a feature request.

P.S. If you’ve built something — a plugin, a library, a code generator, a Grunt task, whatever it is — I’d love to hear from you. Contact us so we can discuss your tool and see if maybe it will be a good fit for an article or tutorial on SitePoint.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.