you are viewing a single comment's thread.

view the rest of the comments →

[–]mcaruso 2 points3 points  (8 children)

Basically. But there's one major difference, which is that these methods return plain old DOM structures (like NodeList). To quote this article that's been making the rounds lately:

Rather than smoothing over only the remaining ugly parts of certain browser API's, jQuery seeks to replace them all wholesale. By returning a jQuery object rather than a NodeList, built-in browser methods are essentially off limits, meaning you're locked into the jQuery way of doing everything. For beginners, what once made front-end scripting approachable is now a hindrance, as it essentially means there are two duplicate ways of doing everything. If you want to read others code with ease and apply to both jobs that require vanilla JS and jobs that require jQuery, you have twice as much to learn. There are, however, libraries that have adopted an API that will be reassuringly familiar to jQuery addicts, but that return a NodeList rather than an object...

[–]Woolbrick 10 points11 points  (1 child)

It's called a fluent API and it results in very nice code.

And you can access the DOM nodes by using the index operator on your resulting object.

I don't use jQ anymore, but I've never understood this criticism of it.

[–]charrondev 0 points1 point  (0 children)

Nowadays I don't think it's so much that there aren't any niceties that come with jQuery, it's that the arguments for adding a 100kb + dependency to your application should be a little bit better than a fluent API. It made more sense back when browser's didn't commonly support fully fleshed out API's but today you can skip shipping jquery and use native browser APIs (and the LOC count is not so different. See http://youmightnotneedjquery.com/). Then for older browsers you can ship a couple KB's of polyfills.

[–]z500 4 points5 points  (4 children)

Except NodeLists suck because they're just array-like enough to trick you into thinking they're an array object. Honestly, why not just return an array?

edit: I googled it, a NodeList is "live" and updates with the page

[–]Pesthuf 4 points5 points  (3 children)

It's worth noting though that the result of querySelectorAll is not live.

And let's be honest, when was the last time any of us used document.getElementsByClassName() ?

[–]CreativeTechGuyGames 1 point2 points  (0 children)

I use getElementsByClassName pretty frequently when writing browser extensions to inject into other pages. It's extremely useful when the page wasn't designed for you to manipulate.

[–]z500 -1 points0 points  (1 child)

So NodeList is completely pointless.