I'm trying to toggle a div using different anchors. I've set up my code in a way that the contents of the div "content" change depending on the clicked anchor. What I need to achieve is not having to click twice to toggle the "content" div, because every .block anchor uses the same slidetoggle. When the second block is clicked after the first one is already open, it now closes the content div. I'd like it to toggle back to a closed position and open itself again. When clicking the second block when its already open, it should just close itself. Seems easy, but I can't wrap my head around it...
HTML:
<div id="thumbnails">
<div title="thumb1" class="block">1</div>
<div title="thumb2" class="block">2</div>
<div title="thumb3" class="block">3</div>
</div>
<div id="content">
<div id="contentblock"></div>
</div>
jQuery:
$(document).ready(function(){
$("#content").hide();
$(".block").click(function() {
$("#content").slideToggle("slow");
});
});
Save the clicked object into a variable, and check if it is matched with the current object(with previous clicked one).
Fiddle