Bug Tracker

Ticket #4599 (closed feature: fixed)

Opened 6 years ago

Last modified 4 years ago

"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

  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

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

Change History

Changed 6 years ago by justinbmeyer

Delegation plugin for jQuery

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed
  • Component changed from unfiled to event

Added in 1.4.2.

Note: See TracTickets for help on using tickets.