0

Here's the code:

var $type = $('#services, #reseller,#technology,#referral'); 
$type.click(function() {
$('#region-nav-reseller').hide();

I can hide #region-nav-reseller when I click on $type (#services, #reseller, #technology or #referral).

This works great, but what about if I would like to exclude #technology and #reseller when I click on $type?

I image something like:

$type-$('#technology, #reseller').click(function() {
    $('#region-nav-reseller').hide();

But this doesn't work (duh ;) )

Codemky
  • 49
  • 4

2 Answers2

2

If I'm understanding your problem correctly, then jQuery's [.not()][1] function should be able to help you. Try:

$($type).not('#technology, #reseller').click(...);

It seems you have a specific purpose in mind for the group of those four IDs. Another idea would be to separate out the things that are clickable from that group. Consider:

var clickable = $("#technology, #reseller");
var nonClickable = $("#services, #referral");
var everything = $(clickable).and(nonClickable);

// Now you can do different things with these different sets
$(everything).whatever();
$(clickable).click(...);
Thomas Kelley
  • 10,187
  • 1
  • 36
  • 43
  • Because it's easier for people to understand :) But yes, it's redundant. `$type.not(...)` is faster/less expensive, and has the exact same effect. – Thomas Kelley Dec 18 '13 at 00:09
2
$type.click(function(ev) {
    if (this.id !== 'technology' && this.id !== 'reseller') {
        $('#region-nav-reseller').hide();
    }
});
mVChr
  • 49,587
  • 11
  • 107
  • 104