Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your toggleClass() call is adding the class to the one clicked, but I don't see you removing the class of the previous clicked. What I would do is something like:</p> <pre><code>$('.expanded').each(function() { $(this).removeClass('expanded'); }); </code></pre> <p><strong>EDIT: Working Example</strong></p> <p>I spent some time in jsFiddle and got <a href="http://jsfiddle.net/7pXpK/" rel="nofollow">this working example</a> (warning, jsFiddler doesn't seem to work in IE8, so use FireFox or Chrome to view the example).</p> <p>First, I dropped the <em>'display: none;</em>' from the <strong>UL.fade_text li div</strong> style in main.css as it's not needed any longer.</p> <p>Next, I added class markers for all the *div*s. I could have probably done something else, but this was a quick-n-dirty example.</p> <p>Last, I re-wrote the JS to be more jQuery-ish. I made a function that will show or hide the divs based on if it finds an anchor tag with the class toggle that also has the class expanded. Then, I added a click event handler to all the anchor tags, again using jQuery, that calls the showHideDivs() function. I also added a call to showHideDivs() in the $(document).ready() so that the initial state is set properly.</p> <p>Here is the new JS code. It could probably be tweeked to optimize things a bit, but it works like I would expect:</p> <pre><code>$(document).ready(function () { function showHideDivs() { $('.showHideDiv').each(function () { if ($(this).prevAll('a.toggle:first').hasClass('expanded')) { $(this).show(); } else { $(this).hide(); } }); } $('a.toggle').click(function () { var addExpanded = !$(this).hasClass('expanded'); $('a.toggle').removeClass('expanded'); if(addExpanded) { $(this).addClass('expanded'); } showHideDivs(); }); showHideDivs(); }); </code></pre> <p>I think the benefits of this approach is that it will gracefully degrade for browsers that have issues with the JS or just have JS turned off. The end result is that those people would see all the div tags expanded.</p>
    singulars
    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.
 

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