30 seconds of code

  Back to Home

toggleClass

browserbeginner

Toggle a class for an element.

Use element.classList.toggle() to toggle the specified class for the element.

const toggleClass = (el, className) => el.classList.toggle(className);