Skip to main content

Bug Tracker

Side navigation

#10762 closed bug (fixed)

Opened November 11, 2011 04:30PM UTC

Closed November 11, 2011 04:32PM UTC

Last modified July 23, 2012 04:50PM UTC

.on() - delegated event handler using selector

Reported by: flezondra@bupllc.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7
Keywords: Cc:
Blocked by: Blocking:
Description

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...

Attachments (0)
Change History (5)

Changed November 11, 2011 04:32PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

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

Changed June 18, 2012 01:01AM UTC by Krinkle comment:2

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.

Changed June 29, 2012 11:17AM UTC by syndicatedshannon comment:3

related: #11993

Changed July 23, 2012 04:50PM UTC by Timmy Willison comment:4

resolution: invalidfixed

Update Sizzle: Minor edits and fixes #10762.

Changeset: a08a18b80adc403dc2914ee6b1ca8752aeddef30

Changed July 23, 2012 04:50PM UTC by Richard Gibson comment:5

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

Changeset: e761e0c6e0561093ff1e52d0cba6ace04daa8798