I am trying to toggle a popup when DIV is clicked. There is multiple DIV's that can be clicked and one popup each inside them.
So far what I have tried:
<div class="popup">Button1
<span class="myPopup">Text inside popup</span>
</div>
<div class="popup">Button2
<span class="myPopup">Text inside popup</span>
</div>
<script>
var el = document.querySelectorAll(".popup");
for(var i =0; i < el.length; i++) {
el[i].onclick = function() { document.getElementsByClassName('myPopup')[i].classList.toggle("show")};
}
</script>
There will always be one popup inside one div, so I assumed if there is click event on div I can get element by class name (myPopup) and use same index to open myPopup, but I can't get it to work. Would like to get this done preferably only using JavaScript.