Skip to content Skip to sidebar Skip to footer

Hide All Div's Except One

I'd like to hide a complete div container except one div. So, on startup just show div id'box_5' and hide the rest. When i click button 1 show everything and when i click button 2

Solution 1:

Change

$('#wrapper').not(":eq(#box_5)").hide(); 

to

$('#wrapper').not("#box_5").hide();

Note: Removed the eq selector. eq selector works on the index and in your case you don't need eq selector as you know the ID of the div.

Also please change your handler functions like below,

$('#button_1').click(function() {
    $('#wrapper').show();
});

$('#button_2').click(function() {
    $('#wrapper').not("#box_5").hide();
});

Solution 2:

Add the element you want to hide to your selector, in this case the "div" elements inside the "wrapper" element. Also, fixed some of the other formatting of the selectors.

    $('#wrapper div').not("#box_5").hide();
    $("#button_1").click(function() {
        $('#wrapper div').show();
    });
    $("#button_2").click(function() {
        $('#wrapper div').not("#box_5").hide();
    });

Post a Comment for "Hide All Div's Except One"