Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2011, 02:51 AM   PM User | #1
Paramasivan
New Coder

 
Join Date: May 2011
Posts: 20
Thanks: 5
Thanked 1 Time in 1 Post
Paramasivan is an unknown quantity at this point
jQuery hide / show elements

I have 2 elements cols3 and cols4. If either one is hidden then by clicking a button that element is to be displayed.
But if both elements are hidden then by clicking a button only element col3 is to be displayed.

I tried with the following code :

$('#plusexp')
.click(function() {
if ($('.cols3:visible')) {
if ($('.cols4:hidden')) {
$('.cols4').show();
}
}
else if ($('.cols4:visible')) {
if ($('.cols3:hidden')) {
$('.cols3').show();
}
}

$('.cols3').show();

});

but if both are hidden, by clicking the button both are displayed instead of only cols3.

Any help?
Paramasivan is offline   Reply With Quote
Old 11-27-2011, 11:03 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Try it with wrapping an else {} statement around the last function.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 11-27-2011, 05:11 PM   PM User | #3
Paramasivan
New Coder

 
Join Date: May 2011
Posts: 20
Thanks: 5
Thanked 1 Time in 1 Post
Paramasivan is an unknown quantity at this point
I have done with the following code:

Code:
$('#plusexp').click(function() {
    var $cols3 = $('.cols3');
    if ($cols3.is(':visible')){
        $('.cols4').show();
    };
    $cols3.show();
});
The following code also works :

Code:
$('#plusexp').click(function() {
    if ($('.cols3').is(':hidden')) {
        $('.cols3').show();
    } else {
        if ($('.cols4').is(':hidden')) {
            $('.cols4').show();
        }
    }
});
Paramasivan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:22 PM.


Advertisement
Log in to turn off these ads.