There are some photos in the gl block. How do I get src photos that I click on?
Here is an example (simplified, because without a solution with img, it makes no sense to write further than it):
<div id="pic"> <img src="img/img-1.jpg" alt=""> <img src="img/img-2.jpg" alt=""> <img src="img/img-3.jpg" alt=""> <img src="img/img-4.jpg" alt=""> <img src="img/img-5.jpg" alt=""> </div>
By pressing any of these images performs the same function (opening a photo in a modal window). I'm having difficulty getting the src of the photo I clicked on. I'm trying to get all the photos in the block using:
pic.getElementsByTagName('img')
, and then get getAttribute(src)
But it does not work. It turns out to get a src photo if I specify:
pic.getElementsByTagName('img')[0]
and above ([1] [2], etc.). Then everything works well for me.
As you understand, in the case above, I will take src only for that img which I will indicate [the number], and I need to catch by what img the click was made.
PS please, without ready codes. Only hints how to do it.
<img onclick="hey(this);"/>
thenfunction hey(x){ console.log(x.src); }
function hey(x){ console.log(x.src); }
- teran