Duplicated event binding with jQuery -
i'm having problem duplicated event binding while using jquery.
i have menu items loads portions of html, javascript , css code via ajax in container. each portion of code binds events elements shown within. when menu element clicked twice event binding done again, events fired several times when called.
i solved with:
$([el1, el2, el3]).each(function(index, item){$(item).off('click')});
and reassign corresponding click event elements.
i think should more elegant solution this.
another way i've found use schema
$(document).on('click', '#test-button',function(e) { if(e.handled !== true) // prevent event triggering more once { alert('clicked'); e.handled = true; } });
the jquery .one() method you're looking for. i'd have left comment don't have enough reputation.
Comments
Post a Comment