Menu

gitpiper

toggleClass javascript Code Snippet in 2023

browserbeginner

Last Updated: 4 June 2023

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 June 2023

Subscribe to our Newsletter

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

© 2023 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! ✌️