Problem with event handlers and DOM [SOLVED] | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Problem with event handlers and DOM [SOLVED]

https://drive.google.com/file/d/1Y1FPxcNWdv2IUTHSUmfjbvlUWCf_L8lp/view?usp=drivesdk This is a link to the video of my problem Here is the code JS varĀ pageĀ =Ā document.querySelectorAll(".details"); varĀ btnĀ =Ā document.querySelectorAll("button"); varĀ bookĀ =Ā document.querySelector(".card"); varĀ placeĀ =Ā 0; for(varĀ iĀ =Ā 0;Ā iĀ <Ā btn.length;Ā i++){ Ā Ā Ā Ā  placeĀ =Ā i; Ā Ā Ā Ā btn[i].addEventListener("click",Ā function(){ page[place].style.transformĀ =Ā "rotateY(-135deg)"; Ā Ā Ā Ā }); } book.addEventListener("mouseleave",Ā function(){ for(varĀ iĀ =Ā 0;Ā iĀ <Ā page.length;Ā i++){ page[i].style.transformĀ =Ā ""; } }); The first button worked fine But other buttons are not working Please tell me a solution for it. You can Debug at Codepen https://codepen.io/sarthakg043-the-selector/pen/jOOVyNQ

19th Oct 2019, 2:22 PM
Sarthak Gupta
Sarthak Gupta - avatar
4 Respostas
+ 2
https://code.sololearn.com/WFM0OdR6Hf1B/#js
19th Oct 2019, 3:07 PM
MO ELomari
+ 3
For the sake of learning and for others who will read and may find this useful later on, would you mind to explain about the fix please Mohamed ELomari Thanks a bunch šŸ‘
19th Oct 2019, 4:22 PM
Ipang
+ 2
Mohamed ELomari Thank you so much sir.šŸ˜‡
19th Oct 2019, 3:31 PM
Sarthak Gupta
Sarthak Gupta - avatar
+ 2
Ipang that's not a big deal. I found a new and more easy fix. Just replace var with let in the previous code and everything will go well.
29th Nov 2019, 4:36 PM
Sarthak Gupta
Sarthak Gupta - avatar