I have a function that uses getElementById and it has been working great. Now I have a page where I call it more than once on the page. The first one works but the rest don't. What do I need to do to make multiples work on one page?
Link provided to other question doesn't answer my question. I'm not getting an error. It's just not doing anything when used more than once. It works on the first element, but not any others.
<script>
var modal = document.getElementById('myModal');
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
modal.style.display = "none";
}
</script>