SlideUp multiple divs

How can I make sure multiple divs are pulled over? Right now I have this function:

$("div#personal").click(function() { 
  $("div.1").slideUp("slow", function () { $("div.2").slideDown("slow") } ); 
});

      

What I would like to do is make sure that all divs that were named:

  • Div. 1
  • div.2 EXCEPT THIS ONE
  • div.3
  • div.4
  • div.5

overlays except for the second div.

+2


source to share


1 answer


You can use the not selector to prevent one (or more) of them from sliding up:

$("div#personal").click(function() { 
  $("div :not('#idofseconddiv'").slideUp("slow");
});

      

It would be nice to give these divs a generic css class so that the selector doesn't select all divs on your page:



$("div#personal").click(function() { 
  $("div.someClass :not('#idofseconddiv')").slideUp("slow");
});

      

If you are using numbered class names in your divs, you may need to use starts with an attribute filter :

$("div#personal").click(function() { 
  $("div[class^=yourClass] :not('#idofseconddiv')").slideUp("slow");
});

      

+5


source







All Articles