Ticket #4599 (closed feature: fixed)
"Better" Event delegation
| Reported by: | justinbmeyer | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.4 |
| Component: | event | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Although live is a great step forward ... I wonder if jQuery would support event delegation that
- Didn't need to query the dom.
- Could delegate from any element (not just documentElement)
For example: $('.some_widget').delegate('a.destroy', function(ev){ })
This is really important if you want to have different things on the page that use event delegation but don't want to muck up other delegates. You can always get the basic live like:
$().delegate('click', function(){})
What's more, delegation event should be called in order by depth and be stoppable. For example: <div class='some_widget'>
<div id='thing'><a>hi</a></div>
</div>
$('.some_widget').delegate('#thing', function(e){
e.stopDelegation()
}) $('.some_widget').delegate('a', function(e){
never called
})
The second function would never be called.
Finally, the following events should work (which don't in live)
submit, focus, blur, change.
This is basically all the functionality in the attached delegate.js file.
However, it uses browser sniffing. I'd like to explore ways of getting around this. This might be difficult w/o implementing synthetic events. Is there a way to tell which event bubble/capture, or see that change is really weird in IE (and a little in Safari).
This is an AMAZING feature and I'd really like to help add it. Right now it is 384 lines. I'm sure I could get it smaller.
Attachments
Change History
Changed 4 years ago by justinbmeyer
-
attachment
delegate.js
added
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Delegation plugin for jQuery