jquery - shortcut for event handling doing off+on+return false -
i find myself doing lot of:
jelem.off('click').on('click', e => { somefunc(e); return false; } );
or
jelem.off('submit').on('submit', e => { somefunc(e); return false; } );
two things repeat here - off
before on
, return false;
is there way me extend jquery add shortcut such 'myon' that:
jelem.myon('click', e => somefunc(e));
will equivalent jelem.off('click').on('click', e => { somefunc(e); return false; } );
you may create own jquery plugin. hope problem.
$.fn.myon = function(e, option){ //code here };
reference: https://learn.jquery.com/plugins/basic-plugin-creation/
Comments
Post a Comment