I'm using this basic code to hide one block of text and display another and it works well but what do I need to do to have a second click close the text again? Right now it stays open until something else is selected so one or another is always open after the first selection. I added some close links that work but would prefer to click on the title (or anything else) to close it again. Other similar questions seem to either use jQuery or they hide the link after it has been selected.
function showhide(id) {
if (document.getElementById) {
var divid = document.getElementById(id);
var divs = document.getElementsByClassName('hide');
for (var i = 0; i < divs.length; i++) {
divs[i].style.display = 'none';
}
divid.style.display = 'block';
}
return false;
}
<a onclick="showhide('toggle1');">
<h4>-> Title 1</h4>
</a>
<div class="hide" id="toggle1" style="display:none">
Some text here. <a onclick="showhide('verify');">close</a>
</div>
<a onclick="showhide('toggle2');">
<h4>-> Title 2</h4>
</a>
<div class="hide" id="toggle2" style="display:none">
Other text here. <a onclick="showhide('verify');">close</a>
</div>