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

Thread: multiple if ?

  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts

    multiple if ?

    Hello, I have a jQuery click function that will need to include multiple if conditions, but not sure how it should be laid out. Basically, this is what I'm after-

    $('#test').click(function() {

    [ if- $('#message1').is(':visible') ]

    [ then- $('#message2').fadeIn().fadeOut(); ]

    [ otherwise- $('#message1').fadeIn().fadeOut(); ]

    ALSO...

    [ if- $('#message2').is(':visible') ]

    [ then- $('#message3').fadeIn().fadeOut(); ]

    [ otherwise- $('#message1').fadeIn().fadeOut(); ]

    });

    I need these conditions because there will be times when #message1 or #message2 is already visible by the time I click on #test. And I don't want more than one message to be visible at any time. So how would I accomplish this??

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,678
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    Code:
    $('#test').click(function() {
      if($('#message1').is(':visible')) {
        $('#message2').fadeIn().fadeOut();
      }
      else {
        $('#message1').fadeIn().fadeOut();
      }
      if($('#message2').is(':visible')) {
        $('#message3').fadeIn().fadeOut();
      }
      else {
        $('#message1').fadeIn().fadeOut();
      }
    });
    I don’t know what you intend with chaining fadeIn and fadeOut, though. Basically these will be executed at the same time.

  • #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    if( $(elem).is(':animated') )
    http://api.jquery.com/animated-selector/


  •  

    Posting Permissions

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