Are HTMLCollection and NodeList iterables?
As greiner pointed out, native Symbol.iterator
support for NodeList
was added to the WHATWG's DOM spec in 2014.
Unfortunately, Chrome 51 is the first version of Chrome to support it, and its Beta has only just been released at the time of writing this answer. Also, there's no support in any version of Internet Explorer or Edge.
To add Symbol.iterator
support for NodeList
in all browsers to your code, just use the following polyfill :
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
Unfortunately, not yet. But until they are, you can easily polyfill them like so:
HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
Symbol.iterator
support for NodeList
, HTMLCollection
, DOMTokenList
, and DOMSettableTokenList
was discussed and added to the WHATWG's DOM spec last year.