I've been researching and came across several scripts that allow for toggling the contents of a DIV by clicking on a button, however, they all use IDs.
What I am looking to achieve is similar but using classes instead of IDs. This way, if I want to have multiple DIVs that toggle between hide and show, I won't need to add extra code.
Below is a sample code snippet:
<script language="javascript">
function toggle() {
var ele = document.getElementsByClassName("toggleText")[0];
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "show";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
}
</script>
<a id="displayText" href="javascript:toggle();">show</a> <== click here
<div class="toggleText" style="display: none"><h1>peek-a-boo</h1></div>
Would appreciate any assistance with this matter.
Thank you