This is what I have so far: For example, when I click on button1, content1 shows, when I click on button2, content1 closes and content2 appears. That works so far with this code:
$("#buttons a").click(function(e){
e.preventDefault();
var toShow = $(this).attr('href');
$(".togg").fadeOut();
$(toShow).fadeIn();
});
JSFiddle What I'm trying to do is keep this function, but add some things: if content1 is already open, toggle it when I click on its button (button1), and also toggle it when clicked outside of the content1 div. In short I want to toggle it when clicked anywhere but the div itself.