I currently have four change()
events that fire exactly the same code (see below), so I'm wondering if there is a way of grouping these events in one line to save reapeating code four times?
Thanks.
/** Check for a change to any of the search dropdowns */
$('#job-roles').change(function(e){
letter = $_GET('staff_search');
initiate_staff_search(letter, '<?php echo $staff_search_nonce; ?>', '<?php echo $name_search_type; ?>')
});
$('#ind-services').change(function(e){
letter = $_GET('staff_search');
initiate_staff_search(letter, '<?php echo $staff_search_nonce; ?>', '<?php echo $name_search_type; ?>')
});
$('#bus-services').change(function(e){
letter = $_GET('staff_search');
initiate_staff_search(letter, '<?php echo $staff_search_nonce; ?>', '<?php echo $name_search_type; ?>')
});
$('#indi-services').change(function(e){
letter = $_GET('staff_search');
initiate_staff_search(letter, '<?php echo $staff_search_nonce; ?>', '<?php echo $name_search_type; ?>')
});
$('#job-roles, #indi-services, #ind-services, #bus-services').change(function(e){
letter = $_GET('staff_search');
initiate_staff_search(letter, '<?php echo $staff_search_nonce; ?>', '<?php echo $name_search_type; ?>')
});
Option 1: give them all the same class and attach the event to all of them $('.someClass').change(...)
Option 2: Group the event: $('#job-roles, #ind-services, ... ').change(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With