What I'm trying to do is have an image slider with buttons on the bottom of the image that will display corresponding information of the image in a modal.
<div class=swipeManual>
<c:forEach var = "tempCustomer" items = "${customers}">
<img id="imgS" src="${pageContext.request.contextPath}/resources/images/${tempCustomer.image}" style="z-index:-2" >
<button class="buttonImg myBtn" type="button" style="z-index:-1">Click Me!</button>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>${tempCustomer.description}</p>
</div>
</div>
</c:forEach>
Here is the JavaScript
<script>
var buttons = document.querySelectorAll('.buttonImg');
function clickHandler(em) {
var modal = document.getElementById(em);
modal.style.display = "Block";
}
for (var i = 0; i < buttons.length; i++) {
(function () {
var but = buttons[i].parentNode.id;
buttons[i].addEventListener("click", function() { clickHandler(but)}, false);
}()); // immediate invocation
}
</script>
The problem is that only the first button works on the carousel, that is to open up the modal with the images's description, and the rest doesn't work. I think I'm looping the buttons incorrectly because only the first button works.
Image 1
Image 2