Classlist.remove() not working

The code below works when adding but not when removing. I am not sure why.
Here is the codepen https://codepen.io/julioperez224-og/pen/Pombdaq

const closeBtn = document.getElementById("close-container");
const modal = document.getElementById("modal");

function expanding(){
  modal.classList.add("expand");
  closeBtn.classList.add("display");
}

function disapear(){
  closeBtn.classList.remove("display");
  modal.classList.remove("expand");
  console.log("disapear")
}

modal.addEventListener("click", expanding);
closeBtn.addEventListener("click", disapear);

Notice that close-container div is a part of modal div, so when closeBtn is clicked it triggers as well event for the modal.

Great catch, I did not even notice that. Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.