jQuery fadeToggle/fadeout function I have the following code to open and close some popup divs. I'd like to know whether there is a shorter solution to close the currently opened divs, as soon as another div is opened, so that there is only one open div.

The current solution works as you can see in this jsFiddle, but I guess it is a bit inconvenient.

jQuery:

$('.details').hide();
$('#item-a').click(function () {
$('#detail-1').fadeToggle(600);
 $('#detail-2,#detail-3').fadeOut("slow");
});

$('#item-b').click(function () {
$('#detail-2').fadeToggle(600);
 $('#detail-1,#detail-3').fadeOut("slow");
});

$('#item-c').click(function () {
$('#detail-3').fadeToggle(600);
 $('#detail-1,#detail-2').fadeOut("slow");
});

$('.btn-close').click(function () {
 $(this).parent().parent().fadeOut("slow");
});


HTML:

&lt;div id="content"&gt;
&lt;ul class="list-1"&gt;
    &lt;li class="topic-a" id="item-a"&gt;
        &lt;p class="shortinfo"&gt; item a &lt;/p&gt;
    &lt;/li&gt;
    &lt;li class="topic-b" id="item-b"&gt;
        &lt;p class="shortinfo"&gt; item b &lt;/p&gt;
    &lt;/li&gt;
    &lt;li class="topic-b" id="item-c"&gt;
        &lt;p class="shortinfo"&gt; item c &lt;/p&gt;
    &lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;
&lt;div class="block"&gt;
  &lt;div class="details" id="detail-1"&gt;
    &lt;p&gt;&lt;a class="btn-close"&gt;close&lt;/a&gt;
    &lt;/p&gt;
    &lt;p&gt; Some detailed text 1.. &lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="details" id="detail-2"&gt;
    &lt;p&gt;&lt;a class="btn-close"&gt;close&lt;/a&gt;
    &lt;/p&gt;
    &lt;p&gt; Some detailed text 2.. &lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="details" id="detail-3"&gt;
    &lt;p&gt;&lt;a class="btn-close"&gt;close&lt;/a&gt;
    &lt;/p&gt;
    &lt;p&gt; Some detailed text 3.. &lt;/p&gt;
  &lt;/div&gt;
 &lt;/div&gt;
You can use the not function to get all the details elements except one:

function show(sel) {
  var el = $(sel);
  el.fadeToggle(600);
  $('.details').not(el).fadeOut("slow");
}

$('.details').hide();

$('#item-a').click(function () {
  show('#detail-1');
});

$('#item-b').click(function () {
  show('#detail-2');
});

$('#item-c').click(function () {
  show('#detail-3');
});

$('.btn-close').click(function () {
  $(this).parent().parent().fadeOut("slow");
});