Any HTML guru here? I can’t seem to figure out how to make this function
more generic… as in I don’t want to “hardcode” ‘myPopup’ but rather somehow
pass the ID of the span to the function.
<script>
// When the user clicks on div, open the popup
function doPopup() {
var popup = document.getElementById('myPopup');
popup.classList.toggle('show');
}
</script>
<div class='popup' onclick="doPopup()">Click me to toggle the popup!
<span class='popuptext' id='myPopup'>A Simple Popup!</span>
</div>
I tried this and it didn’t work
<script>
// When the user clicks on div, open the popup
function doPopup(id) {
var popup = document.getElementById(id);
popup.classList.toggle('show');
}
</script>
<div class='popup' onclick="doPopup('myPopup')">Click me to toggle the popup!
<span class='popuptext' id='myPopup'>A Simple Popup!</span>
</div>
note : there is a bunch of CSS to format the popup etc… which I did not include here