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 ;) )

1
  • Couldn't you just remove them from the variable itself? so var $type = $('#services,#referral');? Commented Dec 18, 2013 at 0:09

2 Answers 2

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(...);
Sign up to request clarification or add additional context in comments.

1 Comment

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.
2
$type.click(function(ev) {
    if (this.id !== 'technology' && this.id !== 'reseller') {
        $('#region-nav-reseller').hide();
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.