#14569 closed enhancement (worksforme)
easy way to find out which node matched the selector
Reported by: | bill | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | high | Milestone: | tbd |
Component: | Events | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
dojo/on supports event delegation:
on(document, ".myClass:click", clickHandler);
However, in the case where the click occurred on a subnode of .myClass, evt.target points to the subnode rather than the .myClass node. It's apparently difficult to find out which .myClass node received the click event.
Would be nice if there evt.currentTarget pointed to the .myClass node rather than the document, or if the second argument to clickHandler() was the .myClass node, etc.
You can see this problem in dijit/_MenuBase.js, in the handlers setup in postCreate(), and how they have to recompute which node matched the selector by (in this case) calling getEnclosingWidget():
on(this.containerNode, on.selector(".dijitMenuItem", mouse.leave), lang.hitch(this, function(evt){ this.onItemUnhover(registry.getEnclosingWidget(evt.target)); })),
Change History (3)
comment:1 Changed 9 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 Changed 9 years ago by
Ah OK thanks. I added that to the documentation, as it didn't seem to be there
|this| points to the node that matched the selector. Of course you have to use a function that is not hitched to access it.