Following your suggestion from the other post. I have modified the code so that it will toggle open when first clicked and close the second time it is clicked. And it will close all if more than one is open.
Code:
function hideAll() {
for (i=0; i < document.getElementsByTagName("span").length; i++){
document.getElementsByTagName("span")[i].style.display = 'none';
}
}
function showInfo(id) {
element =document.getElementById(id);
if (element.style.display=="none"){
element.style.display = 'block';
}else{
hideAll();
// document.getElementById(id).style.display ="none";
}
return false;
}
HTML Code:
Then in the HTML I would do something like:
<div>
<a onclick="return showInfo('Google');">What is Google</a>
</div>
<div>
<a onclick="return showInfo('Yahoo');">What is Yahoo</a>
</div>
<span id="Google" style="display:none">
<div>Here would be some info about Google.</div>
<a href="http://www.google.com">Go to Google</a>
</span>
<span id="Yahoo" style="display:none">
<div>Here would be some info about Yahoo.</div>
<a href="http://www.yahoo.com">Go to Yahoo</a>
</span>
But what I want to do is keep only one open at a time. If google is open and i click yahoo, I want google to close and yahoo to open and vice versa. Trying to figure out how to do this.
Bookmarks