4 ms·
I wanted to reply: document.querySelectorAll("td").map(function (elm) { console.log(elm); }) But apparently a nodelist isn't array enough to get the map f
by jauco 14y ago
I 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/