let containsClass = element.classList.contains('my-class'); element.classList.toggle('my-class', !containsClass);