Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's another working version - a bit cleaner.</p> <p>HTML markup - added <code>.arrow</code> class and fixed IDs:</p> <pre><code>&lt;h1 id="ticket_thread_1" class="ticket_thread_h1"&gt;Thread # 1 &lt;span id="ticket_arrow1" class="arrow down"&gt;&amp;nbsp;&lt;/span&gt;&lt;/h1&gt; &lt;div class="parent"&gt; &lt;div class="sub_thread"&gt;&lt;p&gt;Thread Messages #1 1&lt;/p&gt;&lt;/div&gt; &lt;div class="sub_thread"&gt;&lt;p&gt;Thread Messages #1 2&lt;/p&gt;&lt;/div&gt; &lt;/div&gt; &lt;h1 id="ticket_thread_2" class="ticket_thread_h1"&gt;Thread # 2 &lt;span id="ticket_arrow2" class="arrow down"&gt;&amp;nbsp;&lt;/span&gt;&lt;/h1&gt; &lt;div class="parent"&gt; &lt;div class="sub_thread"&gt;&lt;p&gt;Thread Messages #2 1&lt;/p&gt;&lt;/div&gt; &lt;div class="sub_thread"&gt;&lt;p&gt;Thread Messages #2 2&lt;/p&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>JavaScript - cached selectors:</p> <pre><code>$(document).ready(function(){ $arrows = $('.arrow'); $parents = $('.parent'); $('h1').click(function(){ if ($(this).next('.parent').hasClass('showMe')){ $parents.removeClass('showMe').hide(); // Just in case make all arrows point down: $arrows.removeClass('up').addClass('down'); } else { $parents.removeClass('showMe').hide(); $arrows.removeClass('up').addClass('down'); $(this).find('.arrow').addClass('up'); $(this).next('.parent').addClass('showMe').show(); } }); /** Hides all sub threads **/ $parents.hide(); }); </code></pre> <p>Working jsfiddle: <a href="http://jsfiddle.net/jfrej/cs87W/8/" rel="nofollow">http://jsfiddle.net/jfrej/cs87W/8/</a></p> <p>If you can, you should start using the latest jQuery. The version 1.3.2 in the jsfiddle is way out of date - I left it in to ensure my solution works with that version too.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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