Is there a way to combine these jQuery calls? No real reason other than to tidy up my code a little.
$("#myForm input").blur(function() {
saveForm();
});
$("#myForm :radio, #myForm :checkbox").click(function() {
saveForm();
});
asked Oct 31, 2016 at 4:31
Brad
1,0671 gold badge10 silver badges24 bronze badges
1 Answer 1
use like below for click and blur
$('#myForm input, #myForm :radio, #myForm :checkbox').on('click blur', function () {
saveForm();
});
answered Oct 31, 2016 at 4:40
Mani
2,6562 gold badges23 silver badges44 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Brad
Thanks Mani, @Tushar made a similar suggestion in the comments to my original question which is a bit cleaner than this solution.
lang-js
saveForm()rather than with these two seperate functions.changeevent oninputelements.changeevent is the way to go.$("#myForm input, #myForm :radio, #myForm :checkbox").change(function() { saveForm(); });.change(saveForm)is a lot tidier. There's no need for the anonymous function if all it does is callsaveForm()with no arguments.