Search code examples
jqueryhtmlfading

How to fade all divs in a container except one with jQuery?


I've got this:

$("#id").click(function() {
    $('.swoosh div').fadeOut('fast', function(){
        $('.template').fadeIn('fast');
    });
});

.swoosh is the container div, and .template is the div that i want to remain when i click on #id, while all other divs inside .swoosh disappear.

I feel a bit silly, but I've played around for ages to no avail. Please help a brother out.


Solution

  • You can probably use the not[doc] selector

    $("#id").click(function() {
        $('.swoosh div:not(.template)').fadeOut('fast');
    });