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 comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
Changed June 18, 2012 01:01AM UTC by 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.
This isn't a bug since the selector is invalid; please ask for help on the forum.