Menu

gitpiper

toggleClass javascript Code Snippet in 2024

browserbeginner

Last Updated: 27 December 2024

Toggles a class for an HTML element.

  • Use Element.classList and DOMTokenList.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

javascript snippet similar to toggleClass For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️