Selecting elements of the DOM

Asked

Viewed 50 times

0

I am trying to select a DOM element via js to perform an action by clicking. However, the program does not respond to the click. How should I proceed?

follows the code!

const modalOverlay = document.querySelector('.modal_overlay')
const cards = document.querySelectorAll('.card')

for (let card of cards) {
  card.addEventListener("click", function(){
    modalOverlay.classList.add('active')
  })
}

document.querySelector(".close_modal").addEventListener('click', function() {
  modalOverlay.classList.remove('active')
})
  • cara pq vc does not use foreach() instead of for (Let card of cards)

  • complementing what the colleague said: const modalOverlay = Document.querySelector('. modal_overlay'); const cards = Document.querySelectorAll('. card'); cards.foreach(Function(card){ card.addeventlistener("click", Function(){ modalOverlay.classList.add('active'); }) }); Let test = Document.querySelector(". form-input"); test.addeventlistener('click', Function(){ modalOverlay.classList.remove('active') });

  • Thanks guys , I managed to solve here. Thank you so much for your help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.