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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -