Reputation: 2661
Pretty simple syntax question.
Can I have more one event handler in a change function (or other functions, while I'm at it)?
So something like this:
$("#ctlPerson").change(function() {
to something like this
$("#ctlPerson", "#ctlPerson2", "#ctlPerson3" ).change(function() {
EDIT:
Ok you guys seem to think this works. But it doesn't.
If I were to have
$("#ctlPerson").change(function() {
and
$("#ctlPerson2").change(function() {
these would both would. However, this:
$("#ctlPerson", "#ctlPerson2").change(function() {
does not work for me
Upvotes: 0
Views: 40
Reputation: 123473
Not as separate strings. jQuery()
doesn't use multiple arguments in that manner.
But, a single string can use the Multiple Selector:
$("#ctlPerson, #ctlPerson2, #ctlPerson3").change(function() { ... });
Example: http://jsfiddle.net/XNY7E/
Though, you might consider assigning common class
names to each element and using a class selector:
<select id="ctlPerson" class="ctlPeople"></select>
<select id="ctlPerson2" class="ctlPeople"></select>
<select id="ctlPerson3" class="ctlPeople"></select>
$('.ctlPeople').change(function () { ... });
Upvotes: 4
Reputation: 76219
$("#ctlPerson, #ctlPerson2, #ctlPerson3" ).change();
http://api.jquery.com/multiple-selector/
Upvotes: 1