snippet #4 - chainable classList

published on the 10th of Nov, 2019

Let's keep this one short:

function classList(el) {
  const list = el.classList

  return {
    add: function(c) { list.add(c); return this },
    toggle: function(c) { list.toggle(c); return this },
    remove: function(c) { list.remove(c); return this }
  }
}

And then chain away!

classList(el).remove('foo').add('bar').toggle('baz')

Find me on

Proudly generated with Saber,

safely hosted on Netlify.