<div class="popup" onclick="myFunction()">Click me!
<span class="popuptext" id="NewPopup">Your text</span>
</div>
Best answer
<div class="popup" onclick="myFunction()">Click me!
<span class="popuptext" id="NewPopup">Your text</span>
</div>
Make a hidden popup box with CSS and show it by toggling a class with a small JavaScript function.
<style>
.popup { position: relative; display: inline-block; cursor: pointer; }
.popup .popuptext {
visibility: hidden; width: 160px;
background: #555; color: #fff; text-align: center;
border-radius: 6px; padding: 8px;
position: absolute; bottom: 125%; left: 50%;
margin-left: -80px; z-index: 1;
}
.popup .show { visibility: visible; }
</style>
<div class="popup" onclick="myFunction()">Click me!
<span class="popuptext" id="myPopup">Your text</span>
</div>
<script>
function myFunction() {
document.getElementById("myPopup").classList.toggle("show");
}
</script>The span is hidden by default. Each click on "Click me!" runs myFunction(), which adds or removes the show class, making the popup appear above the text or disappear. The id used in the script must match the span's id.
Log in or create a free account to answer this question.