Files
30-seconds-of-code/snippets/toggleClass.md
2017-12-28 23:46:33 +02:00

343 B

toggleClass

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);
toggleClass(document.querySelector('p.special')[0],'special') // The paragraph will not have the 'special' class anymore