Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#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:


dojo/on supports event delegation:

on(document, ".myClass:click", clickHandler);

However, in the case where the click occurred on a subnode of .myClass, 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){

Change History (3)

comment:1 Changed 10 years ago by Kris Zyp

Resolution: worksforme
Status: newclosed

|this| points to the node that matched the selector. Of course you have to use a function that is not hitched to access it.

comment:2 Changed 10 years ago by bill

Ah OK thanks. I added that to the documentation, as it didn't seem to be there

comment:3 Changed 10 years ago by bill

In [27509]:

Take advantage of on() returning node that matched the selector as "this". Refs #14569 !strict.

Note: See TracTickets for help on using tickets.