Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    20
    Thanks
    5
    Thanked 1 Time in 1 Post

    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?

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,482
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Try it with wrapping an else {} statement around the last function.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    20
    Thanks
    5
    Thanked 1 Time in 1 Post
    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();
            }
        }
    });


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •