I am dealing with a legacy system and I can't rewrite the whole css.
So I find myself in need to toggle 2 classes on the same element when another one is clicked (imagine clicking on a button to hide/show a modal).
The following is the code for the modal.
Where the modal window is by default .hidden
(without the class "visible") and on click it is .visible
(without the class "hidden").
function openModal(modalID) {
document.getElementById(modalID)
.classList.toggle('hidden');
document.getElementById(modalID)
.classList.toggle('visible');
}
I agree to accept the
<a href="#"
onclick="openModal('tandcmodal')">
terms and conditions
</a>
of this website.
<div id="tandcmodal"
class="hidden">
Content of the modal
</div>
So, I believe there must be a way to toggle more than one class at once with .toggle()
.
Or isn't it?