Multiple img onclick function | Sololearn: Learn to code for FREE!

+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

4/7/2019 12:34:05 PM

FlyiiingDani

4 Answers

New Answer

+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

+1

Thanky you!

0

There is no span with class="close", which causes the error.

0

Sry i just forgott this part of the code. Here is the reworked code: https://code.sololearn.com/WDtN2J25PXO2/?ref=app