Search code examples
javascriptjqueryhtmlweblivequery

jQuery - code using element.on('click', ... inserting html onto page without the live "feature"


Existing code already uses .on to bind all over the place. I need to insert html into the page, but I have my own logic for initializing the html and binding the clicks and therefore for the piece I am about to insert, I would not like the live features of jQuery. but run it through my own binders.

Is there a way to do that? To turn off the autobinding for .on temporarily ?


Solution

  • Yes, jQuery-natively, there is off which can unbind existing events, either all or particular (namespaced) and there is event.stopImmediatePropagation() that allows you to stop event bubbling and tells the program not to execute any additional event handlers. (you need to bind before the other handlers in order to prevent them from executing, first to come is the first to be served).

    Particularly to LiveQuery, there is expire. Read doc at https://github.com/hazzik/livequery/blob/master/README.md

    But you can always affect what a plugin does with native techniques if you are hackish enough. I had to do a lot of things like that on sites created by others.