Brian
Brian

Reputation: 27392

jQuery event on select change except one select

I have a page with several select buttons. I would like for a function to be called in jQuery any select function except for say one with id="Select1" is changed. I know that I can link the function to each select that I want liked to the event, but it would be much more convenient to specify those that should be excluded than list all that should be included.

Would it be possible for one specific class of selects to cause a change?

Upvotes: 2

Views: 1100

Answers (2)

rahul
rahul

Reputation: 187040

$("select.myselectClass").change(function(){
});

will fire the change event for select events with class myselectClass only.

Better to select the combos for which you want to fire the event rather than using the :not. If you want to remove event for more than one select box then it would be more complicated.

Upvotes: 0

David Hedlund
David Hedlund

Reputation: 129792

$('select:not(#Select1)');

or if you're specifying several to exclude:

$('select:not(.excludeClass)');

the same can be achieved with method chaining:

$('select').not('#Select1');

Upvotes: 5

Related Questions