Ticket #11891 (closed enhancement: invalid)
catch-all event handler
|Reported by:||faassen||Owned by:|
In jQuery 1.6.4, registering an event handler on $(document) or $(window) would work as a catch-all event handler, even for events on elements that are not attached to the DOM. In jQuery 1.7 this changed
See also this jsFiddle demonstrating the difference between 1.7 and 1.6.4; in 1.6.4 this fires twice, but if you switch to 1.7.2 it'll fire only once.
My code was relying on this catch-all event handling behavior, but broke. I understand why this fix was made, but would it be possible to add a feature to jQuery that would allow the developer to register a catch-all event handler that will be triggered if no element-level (or document level or window level) event handler can be found? This would simplify my code; now I have to check whether the event was handled at all, and if not, trigger the catch-all handler, which is more ugly than I'd like it to be. I don't know what "this" should be in such a handler, but ev.target is still available to do something interesting.
(I tried to look for such a feature in the code but I couldn't find anything - sorry if I missed something.)
- Status changed from new to closed
- Resolution set to invalid