Bug Tracker

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:


Although live is a great step forward ... I wonder if jQuery would support event delegation that

  1. Didn't need to query the dom.
  2. 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>


$('.some_widget').delegate('#thing', function(e){


}) $('.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)

delegate.js (14.4 KB) - added by justinbmeyer 14 years ago.
Delegation plugin for jQuery

Download all attachments as: .zip

Change History (2)

Changed 14 years ago by justinbmeyer

Attachment: delegate.js added

Delegation plugin for jQuery

comment:1 Changed 13 years ago by dmethvin

Component: unfiledevent
Resolution: fixed
Status: newclosed

Added in 1.4.2.

Note: See TracTickets for help on using tickets.