$('#button').click(function() {
todo();
});
$('#input').keydown(function(e) {
if(e.keyCode == 13) {
todo();
}
});
For example, if you click a button or press Enter in the input box to perform the same operation, can it be optimized into the following type of code:
$('#buttonA,#buttonB').click(function(){
todo....
});
Generally I like to use hosting
If your two operations have something in common, you can use the same class name to identify and bind events
If they are of different types, your first method is fine