Opened 14 years ago
Closed 13 years ago
#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: | ||
Blocked by: | Blocking: |
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 (1)
Change History (2)
Changed 14 years ago by
Attachment: | delegate.js added |
---|
comment:1 Changed 13 years ago by
Component: | unfiled → event |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Added in 1.4.2.
Delegation plugin for jQuery