Feature request: remove undelegated events without removing delegated
off()
already supports the opposite of this
To remove all delegated events from an element without removing non-delegated events, use the special value
"**"
.
How about enabling removal of non-delegated events without removing delegated by passing in null or an empty string as the selector?
Here is my use case
on page load my modal module attaches triggers using a delegated listener (to allow for lazy loading content into the page without having to worry about attaching new listeners)
- $('body').on('click.modal', '.modal--trigger', myOpeningCallback)
Then each instance of modal attaches some closing listeners including
- $('body').on('click.modal', myClosingCallback)
myClosingCallback is a curried function created within the scope of myOpeningCallback so after the modal's closed I can't remove that specific listener by referencing the function.
I can think of a few ways of addressing this problem, so it's not a blocker for me, but I think passing in null or '' as the selector to off() would be an elegant addition to the off() API.