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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -