3 ms·
I don't think Array.prototype.forEach.call(el.querySelectorAll(selector)) is complex enough to pull in a new library.
by sinkasapa 13y ago
I don't think Array.prototype.forEach.call(el.querySelectorAll(selector)) is complex enough to pull in a new library.
- hrktb 13y agoIt's not, but then you fall on IE9+ land, and you'll have to check if querySelectorAll returns anything first. The sibling comment points out how a function silently failing when given empty value can be deceiptive. I guess your way of seeing it would be also in line with checking valid values before using them. It's a very sane approach, and it requires more care and attention for each step. I'm not against it, but usually I'm not sure to see a real payoff for very conservative programming in front end DOM manipulation, I tend to prefer taking some performance hit and ignore the nitty gritty details as well as the small errors, as long as it can be recovered at a higher level.