2 ms·
Sorry for being terribly pedantic, but the "vanilla" version just does not do what the jQuery code does: - `this` might not be document - find might return mu
by m90 8y ago
Sorry for being terribly pedantic, but the "vanilla" version just does not do what the jQuery code does:
- `this` might not be document
- find might return multiple elements, not just one
- if nothing matches, jQuery does not throw unlike the vanilla version
I do understand it's just an example, but if you'd consider all the implicit cases the jQuery example covers, you'd end up with a lot more than a single line. I see your point, but using off examples like this don't really sell it too well.
- TekMol 8y agoThese seem to be unintended side effects. From the example it seems the vanilla versions behaviour is what the author wants.
- tracker1 8y agoassuming "this" is an element... `this.querySelector` if you're intending to match multiples... Array.from(document.querySelectorAll(...)).forEach(x => {...}) It's not *that hard... though forEach should be on your dom collection returned, if Array.from exists, but I started shimming Array.from long before either were standard.