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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -