javascript - How to combine different event triggers -
i new jquery , hope can me this.
i have js function triggered various elements / classes difference of them event triggered click , others on keyup etc.
so far have following example works intended wondering if there way combine these difference here trigger (click, keyup etc.) , avoid duplicating code.
if there other suggestions write different please let me know well.
my jquery (example):
$(document).on('keyup', '.calcminus, .calcplus', function(e){ var row = $(e.target); $(row).closest('table').find('td.calcsum').each(function(index){ calculatesums(row, index); }); }); $(document).on('click', '.tradd, .trdelete, .trdown, .trup', function(e){ var row = $(e.target); $(row).closest('table').find('td.calcsum').each(function(index){ calculatesums(row, index); }); }); // ...
my js function:
function calculatesums(row, index){ // stuff }
many in advance, mike
$(document).on('keyup', '.calcminus, .calcplus', combined); $(document).on('click keyup', '.tradd, .trdelete, .trdown, .trup', combined); function combined(e){ var row = $(e.target); $(row).closest('table').find('td.calcsum').each(function(index){ calculatesums(row, index); }); }
Comments
Post a Comment