Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is because, after closing all <code>h4.open</code>, you still <code>slideToggle()</code> the clicked <code>h4</code>.</p> <pre><code>$(document).ready(function() { $('div#winners-table div').hide(); $('div#winners-table h4').click(function(){ var clicked = this; $('div#winners-table h4.open').each(function() { $(this).attr('class', 'closed'); if (clicked != this) { $(this).siblings('div').slideUp(); } }); $(this).toggleClass('open'); $(this).siblings('div').slideToggle(); }); }); </code></pre> <p>^ I added a check where the clicked <code>h4</code> wouldn't <code>slideUp()</code>, so the <code>slideToggle()</code> would do its job as expected.</p> <hr> <p><strong>EDIT</strong></p> <p>Here's my entire HTML file:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { $('div#winners-table div').hide(); $('div#winners-table h4').click(function(){ var clicked = this; $('div#winners-table h4.open').each(function() { $(this).attr('class', 'closed'); if (clicked != this) { $(this).siblings('div').slideUp(); } }); $(this).toggleClass('open'); $(this).siblings('div').slideToggle(); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="winners-table"&gt; &lt;h3&gt;h3&lt;/h3&gt; &lt;ul&gt; &lt;li&gt; &lt;h4&gt;H4&lt;/h4&gt; &lt;div&gt;div1&lt;/div&gt; &lt;/li&gt;&lt;!-- ENDS --&gt; &lt;li&gt; &lt;h4&gt;h4 2&lt;/h4&gt; &lt;div&gt;div 2&lt;/div&gt; &lt;/li&gt;&lt;!-- ENDS --&gt; &lt;li&gt; &lt;h4&gt;h4 3&lt;/h4&gt; &lt;div&gt;div 3&lt;/div&gt; &lt;/li&gt;&lt;!-- ENDS --&gt; &lt;li&gt; &lt;h4&gt;h4 4&lt;/h4&gt; &lt;div&gt;div 4&lt;/div&gt; &lt;/li&gt;&lt;!-- ENDS --&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>As you can see, I copied your HTML and only replaced the ellipses. Tested on Firefox 3.5, Chrome 4 (dev channel), Opera 10, IE6 (via IEs4Linux) on Ubuntu.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload