#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    3

    [Jquery] Collapse other div's


    I have this piece of code. Now i want to make sure that if the user click's another div, the current one collapses..

    Code:
    jQuery(document).ready(function() {
      jQuery(".content").hide();
      jQuery(".heading").click(function()
      {
        jQuery(this).next(".content").slideToggle(500);
      });
    });
    Thanks!
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    13
    You could do something like this:

    Code:
    $('heading').click( function() {
        // find any current active divs and hide and remove class
        $(".active").each( function() {
            $(this).hide();
            $(this).removeClass( 'active' );
        })
        
        $(this).next(".content").slideToggle(500);
        $(this).next(".content").addClass( "active" ); // not sure if you can do this but hopefully you get the idea
    })

IMN logo majestic logo threadwatch logo seochat tools logo