Files
30-seconds-of-code/snippets/toggleClass.md
2020-09-15 21:52:00 +03:00

384 B

title, tags
title tags
toggleClass browser,beginner

Toggles a class for an HTML 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'), 'special');
// The paragraph will not have the 'special' class anymore