4 ms·
I assumed he was talking about document.querySelectorAll in the context of selecting elements, not for additional functionality such as jQuery's fadeIn()
by michaelwww 14y ago
I assumed he was talking about document.querySelectorAll in the context of selecting elements, not for additional functionality such as jQuery's fadeIn()
- bengillies 14y agoIt's the extra functionality that makes it useful though. document.querySelectorAll doesn't even support event listeners or forEach loops. I wouldn't call that extra functionality, I'd call that a basic requirement. It lets you select elements using CSS selectors. That's good and all but if you want to actually do anything with that you're better off using some sort of library that abstracts the awkwardness away (i.e. jQuery).
- jauco 14y agoI wanted to reply: document.querySelectorAll("td").map(function (elm) { console.log(elm); }) But apparently a nodelist isn't array enough to get the map function. sigh.... you could use Array.prototype.map.call(). But this really underlines the value of jQuery: in jQuery you can predict what will happen, in the DOM you can't.
- MatthewPhillips 14y agoYou can, the MDN article has an entire section on it: https://developer.mozilla.org/en-US/docs/DOM/NodeList https://developer.mozilla.org/en-US/docs/DOM/NodeList
- nilliams 14y agoYes, except as that article shows the traditional for loop somehow ends up more palatable than the awkward `forEach.call()` voodoo you have to do to use it on a NodeList, which is a pretty sad state of affairs :/ (Note: I am aware you can alleviate this with toArray type utils [1] but that does seem to be slightly besides the point). [1] http://jsfiddle.net/AhQPU/ http://jsfiddle.net/AhQPU/