4 ms·
With jQuery it's probably like 4 or 5 lines. With plain JS a few more as you have to write your own iterator function. All an accordion does is add an event li
by Touche 10y ago
With jQuery it's probably like 4 or 5 lines. With plain JS a few more as you have to write your own iterator function.
All an accordion does is add an event listener that removes a class from all elements and adds it back to one of them. Then there's a 1 line transition for that class in css.
- talmand 10y agoIs jQuery included in those 4 or 5 lines? One line of CSS in your accordion?
- Touche 10y agoIf you had read the next sentence of my comments you would have seen that it would be a "few more lines" if you didn't use jQuery, basically you need a function like: function eachItem(arrayLike, cb) { return [].slice.call(arrayLike).forEach(cb); } So 3 more lines. If I said you can write a very verbose accordion in under 20 lines would that be good enough for you?
- justinlardinois 10y agoI'm not sure why the actual jQuery library matters here. Chances are if you're using jQuery for an accordion you're also using it for a lot of other things.