javascript - Unbind events on elements that will be added to DOM later -


i have div class="backdrop". added dom when click button. bound event of 'wheel'.

i cannot avoid binding of event(happening through library) want unbind globally.

i tried : $(".modal-backdrop.am-fade").unbind('wheel');

this works have write statement after each time div added dom. i want can write once , apply divs added dom in future

i want can write once , apply divs added dom in future

if code in library you're using adding elements , binding events them, you'll have unbind them go, there's no alternative.

if have way of triggering (the library tells when adds div), you'll have have code respond event.

if don't have way of triggering it, can use mutation observers watch divs being added can unbind them. they're well-supported modern browsers. less modern browsers may have sufficient support old mutation events can use library provides mutation observer polyfill using mutation events (just search "mutation observer polyfill"). worst case, on old browsers, you'll have poll.


of course, best answer either stop using library if doesn't want, or modify (this javascript, after all) doesn't don't want.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -