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