Multiple img onclick function | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 1

Multiple img onclick function

Hello, I tried to use multiple onclick tunction for each image but its not working. So if the image is clicked, it should pop up and gets bigger. Is it possible to use a switch case statement or something to check which image is clicked? Thank you! Here is the code: https://code.sololearn.com/WDtN2J25PXO2/?ref=app

7th Apr 2019, 12:34 PM
FlyiiingDani
FlyiiingDani - avatar
4 Respostas
+ 3
Use a css class for all the displayed images, populate it with the same onclick event. You only need one set of modal image container. The modal would be updated with correct image and capture. I simplified your code here with the same event function, but populate it to all image elements. Practice DRY, don't repeat yourself on coding always would avoid unnecessary errors. https://code.sololearn.com/WTb4eT16ooz2/?ref=app
7th Apr 2019, 1:54 PM
Calvi’≤
Calvi’≤ - avatar
+ 1
Thanky you!
7th Apr 2019, 4:07 PM
FlyiiingDani
FlyiiingDani - avatar
0
There is no span with class="close", which causes the error.
7th Apr 2019, 1:02 PM
Maneren
Maneren - avatar
0
Sry i just forgott this part of the code. Here is the reworked code: https://code.sololearn.com/WDtN2J25PXO2/?ref=app
7th Apr 2019, 1:13 PM
FlyiiingDani
FlyiiingDani - avatar