[Django]-How to change visibility on div multiple times with javascript and css?

3👍

After adding a new class, you must remove the previous class from the element’s classlist. So the modal won’t seem to work anymore after having both classes at the same time.

for ex.

function changeVisibility(modal) {
 if(modal.classList.contains('open-modal')) {
   modal.classList.remove('open-modal');
   modal.classlist.add('close-modal');
 } else {
    modal.classList.remove('close-modal');
    modal.classList.add('open-modal')
 } 
} 
 

0👍

If your trying to do modals, you should use HTML’s <dialog> element (Also see HTMLDialogElement). MDN has a tutorial on it.

Leave a comment