Reputation: 780
I have this jQuery Code:
$('#select-adults-room-1').change( function () {
og.removeErrorsOcio();
});
$('#select-kids-room-1').change( function () {
og.removeErrorsOcio();
});
What is the best way to do it? I know this looks weird, but not sure how to improve it if it's possible. I'm looking for some like this:
$('#select-adults-room-1','#select-kids-room-1').change( function () {
og.removeErrorsOcio();
});
Thanks
Upvotes: 2
Views: 2015
Reputation: 924
Tried to give common class to each element as
$('.your-element').change( function () {
og.removeErrorsOcio();
});
Upvotes: 0
Reputation: 337560
You don't need to pass separate strings, place the comma between the selectors in a single string, like this:
$('#select-adults-room-1, #select-kids-room-1').change(function() {
og.removeErrorsOcio();
});
Also note that you can pass the reference of the function directly to the change()
method, like this:
$('#select-adults-room-1, #select-kids-room-1').change(og.removeErrorsOcio);
Upvotes: 7