from a querySelectorAll I retrieve every objects from a specific class
(list - all the same but with specific value inside...) :
- I create buttons (event) for each objects
- Each object have a specific value
- When clicking on one object. I need to show this specific value contained inside this object.
I'm currently doing it with pure javascript
I use tree HMTL node to move inside and take the data. But whenever, these objects are clicked it's only the last object value come up...
----- EDIT : html added-----
function hello(d)
{
alert("" + d);
}
var Images = document.querySelectorAll('.block-image_carousel-single > figcaption');
for (var i = 0; i < Images.length; i++) {
var Image = Images[i];
Image.addEventListener('click', function (event) {
event.preventDefault();
hello(Image.textContent);
}, false);
}
<div class="block-image_carousel">
<div>
<div class="block-main-image_carousel-display">
<img src="img.png" class="block-image_carousel-display">
<figcaption> Image 1 </figcaption>
</div>
<div class="block-image_carousel-single">
<img src="img.png">
<figcaption> Image 1 </figcaption>
</div>
<div class="block-image_carousel-single">
<img src="img.png">
<figcaption> Image 2 </figcaption>
</div>
<div class="block-image_carousel-single">
<img src="img.png">
<figcaption> Image 3 </figcaption>
</div>
<div class="block-image_carousel-single">
<img src="img.png">
<figcaption> Image 4 </figcaption>
</div>
</div>
</div>
- When clicking on one object. I need to show this specific value contained inside this object.
- But whenever, these objects are clicked it's only the last object value come up...
ANSWER : use let instead of var for image.