Home > Blockchain >  addEventListener multiple use
addEventListener multiple use

Time:06-07

I am making an application according to the youtube tutorial. I already know what the correct solution looks like, but I don't know why such a code does not work. It is only executed once. I check 'Inspector' in the browser and there it shows that the second div got active class, but the second click doesn't work.

document.querySelector('.emoji').addEventListener('click', function() {
  document.querySelector('.open').classList.toggle('active');
  document.querySelector('.closed').classList.toggle('active');
});
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.emoji {
  text-align: center;
  font-size: 20rem;
  cursor: pointer;
  display: none;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.active {
  display: block;
}
<!-- emoji no evil            
  • Related