Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10762 closed bug (fixed)

.on() - delegated event handler using selector

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7
Keywords: Cc:
Blocked by: Blocking:


The plugin I created which uses a <dl> list works fine using this syntax of on():

$dockPanel.on("click","dt",function(e){ HandlePanel($(this)); });

But since my plugin element can be nested within itself, I only want to effect it's direct child level element of 'dt', not all descendant <dt> elements for the <dl>, so what I need is this:

$dockPanel.on("click",">dt",function(e){ HandlePanel($(this)); });

The above syntax does not work using a child selector though...

Change History (5)

comment:1 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

This isn't a bug since the selector is invalid; please ask for help on the forum.

comment:2 Changed 11 years ago by Krinkle

I ran into this today as well: http://jsfiddle.net/pUh3F/

Contrary to the actual implementation, I think the expected behavior is that the delegate selector is interpreted relative to the element that the event handler is bound to.

So if you got a <ul> with potentially nested lists, and you want a delegate selector on the direct children of the list, one would use $('#my-list').on('click', '>li', function () { .. }); But that doesn't work because the selector is not checked including the appropriate context.

I'd like to ask if this can be turned into a feature request. To add support to the delegate selector in .on() for having the selector checked with the bound element as context.

comment:3 Changed 11 years ago by syndicatedshannon

related: #11993

comment:4 Changed 11 years ago by Timmy Willison

Resolution: invalidfixed

Update Sizzle: Minor edits and fixes #10762.

Changeset: a08a18b80adc403dc2914ee6b1ca8752aeddef30

comment:5 Changed 11 years ago by Richard Gibson

Support event delegation with relative selectors. Fixes #10762. Closes gh-860.

Changeset: e761e0c6e0561093ff1e52d0cba6ace04daa8798

Note: See TracTickets for help on using tickets.