4 ms·
It is possible to do that without the variable assignment in JS... [].forEach.call(document.querySelectorAll('div'), function(el) { el.classList.ad
by rcgs 11y ago
It is possible to do that without the variable assignment in JS...
[].forEach.call(document.querySelectorAll('div'), function(el) {
el.classList.add('new');
});
But I don't disagree that the jQuery example is easier to write/read/remember.
Though with frameworks like Angular or React I'm beginning to question whether we should ever be writing code like this at all.
- jackmoore 11y agoAgreed. I mainly use React these days, and directly modifying the DOM is starting to feel dirty.