Home > Blockchain >  Open modal using JavaScript (not jQuery)
Open modal using JavaScript (not jQuery)

Time:03-09

I'm trying to repurpose some code I obtained from Codepen. It's written using jQuery but I want to rewrite the script using JavaScript.

The original codepen (see: enter image description here

CodePudding user response:

Thanks to Indana Rishi, I arrived at the following code, which, while probably not all that elegant, certainly works:

let button = document.getElementById('start');
let body = document.body;
button.addEventListener('click', () => {
    document.getElementById('modal-container').classList.remove('one');
    document.getElementById('modal-container').classList.remove('out');
    document.getElementById('modal-container').classList.add('one');
    body.classList.add("modal-active");
});

let modcon = document.getElementById('modal-container');
modcon.addEventListener('click', () => {
    document.getElementById('modal-container').classList.add('out');
    body.classList.remove("modal-active");
});
  • Related