Skip to main content

Bug Tracker

Side navigation

#4599 closed feature (fixed)

Opened April 28, 2009 06:07AM UTC

Closed June 13, 2010 02:37AM UTC

"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

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>

</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)
  • delegate.js (14.4 KB) - added by justinbmeyer April 28, 2009 06:08AM UTC.

    Delegation plugin for jQuery

Change History (1)

Changed June 13, 2010 02:37AM UTC by dmethvin comment:1

component: unfiledevent
resolution: → fixed
status: newclosed

Added in 1.4.2.