Ive used when a select list's option is changed as an event listener, with something like this:
$('#mySelect').change(function() {
functionToRun();
});
Is it OK to use the event listener more than once? So something like below. I know for this exact example it makes no sense, but for more complicated code with conditionals at work it would be easier for me to maintain my code if I used the event listener twice.
$('#mySelect').change(function() {
functionToRun();
});
//other code
$('#mySelect').change(function() {
functionToRunTwo();
});
Also, I have some code that runs on dom ready and some that runs on window load. Is it OK to use the same event listener in both instances?
It will work as expected: both event listeners will be fired and there is certainly no problem with that. From
jQuery.bind()(which is called internally byjQuery.change()):I am not sure if this answers your second question.