js:
document.querySelector('.target').addEventListener('click', function(event) { event.preventDefault(); var target = document.querySelector('.target'); if (target.classList.contains('active')) { target.classList.remove('active'); } else { target.classList.add('active'); } });
html:
<button class="target">click to add/remove class</button>