I'm trying to create a script that allows users to toggle between different posts, showing one at a time. However, I'm running into an issue where clicking on a new post doesn't hide the content of the previous one. How can I modify the code so that clicking on a new post hides the content of the previous one and only shows the content of the post that's currently selected? I remember doing something similar a year ago but can't seem to figure it out now.
<script type="text/javascript">
function togglePost(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "block") obj.style.display = "none";
else if (obj.style.display = "none") obj.style.display = "block";
else obj.style.display = "none";
}
</script>
<div id="container">
<div id="sidebar">
<h3>Posts</h3>
<p><span onClick="togglePost('q1')">October</span></p>
<p><span onClick="togglePost('q2')">November</span></p>
<p><span onClick="togglePost('q3')">December</span></p>
</div>
<div id="center">
<h1> Main Page of post content</h1>
<p><div id="q1" style="display:none;">October is...testtext testtext testtext</div></p>
<p><div id="q2" style="display:none;">November is...testtext testtext testtext</div></p>
<p><div id="q3" style="display:none;">December is...testtext testtext testtext</div></p>
</div>
<br class="clearfloat" />
</div>