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 08-25-2012, 11:47 AM   PM User | #1
resin
Regular Coder

 
Join Date: Nov 2011
Posts: 142
Thanks: 5
Thanked 0 Times in 0 Posts
resin is an unknown quantity at this point
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??
resin is offline   Reply With Quote
Old 08-25-2012, 12:02 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,598
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Old 08-26-2012, 02:10 PM   PM User | #3
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
Code:
if( $(elem).is(':animated') )
http://api.jquery.com/animated-selector/
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa 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 06:59 PM.


Advertisement
Log in to turn off these ads.