tags:

views:

84

answers:

4

How do i use an "or" statement in jquery, i have two separate statements that i think i can combine to be just one:

$('li.members').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });

$('li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });
+10  A: 
$('li.members, li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });
Ryan Kinal
Also: `$('.brokers-show, .providers-show, .employers-show, .seniors-show').hide()`. (Probably the entire `*-show` suffix could be dropped for a separate CSS class `show`, which could be added and dropped with `addClass()` and `removeClass`…)
Tomalak
+1  A: 

I think you can use Multiple Selector

Jarek
+5  A: 
$('li.members, li.members-active').hover(function() {
    $('.members-show').show();
    $('.members-show, .providers-show, .employers-show, .seniors-show').hide();    
    return false;
  });
Almost - the $().hide() selector needs commas. But +1 for combining those calls.
Ryan Kinal
A: 

Try the Multiple Selector:

$('li.members,li.members-active').hover(function() {
    $('.members-show').show();
    $('.brokers-show').hide();
    $('.providers-show').hide();
    $('.employers-show').hide();
    $('.seniors-show').hide();
    return false;
  });
Aaron Digulla