I’m looking for a clean way to fire one function that may be triggered by two possible events. For example:
$('form').on('submit', function() {
stuff in here...
});
$('input').on('change', function() {
same stuff in here as before...
});
I could do
function doStuff() {
Stuff in here....
}
$('form').on('submit', function() {
doStuff();
});
$('input').on('change', function() {
doStuff();
});
But I was wondering if there was a more elegant way of doing this?
1 Answer