3 ms·
`$(".foo").removeClass("bold")` becomes the wonderfully concise [].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold
by jhpriestley 12y ago
`$(".foo").removeClass("bold")` becomes the wonderfully concise
[].map.call(document.querySelectorAll(".foo"), function(node) { node.classlist.remove("bold"); })
- sfeng 12y agoThis may seem anecdotal, but I can tell you from writing a lot of non-jQueryified code that with modern browsers, applying classes to dozens of elements dynamically can be an anti-pattern. 99% of the time, when doing something which previously would have required that, I can use a single class on a parent element.
- usingpond 12y agoNot if you're in an environment (like mobile) where you want to reduce repaint.
- malandrew 12y agoIn which case you don't want to be using jQuery at all and should instead be using a virtual DOM implementation like virtual-dom, famo.us, react or mithril. https://github.com/Matt-Esch/virtual-dom https://github.com/Matt-Esch/virtual-dom
- ulisesrmzroche 12y agoWhat if you don't have the option to all of a sudden bust out a new framework? Some of these scenarios are just unrealistic.
- ulisesrmzroche 12y agoNo, you're going to mess with repaints and renders. It is not an anti pattern.
- ahoge 12y agoWith spread and fat arrows: [...document.querySelectorAll('.foo')].forEach(node => node.classList.remove('bold'));