Reputation: 32530
Given a generic handler bound to a series of links with YUI, how do I find out which link triggered the event?
YUI().use('node', function (Y) {
var list = Y.one('#studentList'), links;
links = list.all('a');
links.on('click', function (e) {
alert(this.get('id')); // this just shows a comma delimited list of all ids
});
});
I suppose I could bind each link individually instead of using the "on" idiom on the links list, but it seems odd to me that YUI would not provide access to the DOM node. Digging into the event object shows several private fields that look like the DOM node, but surely there must be a safe way of doing this.
Upvotes: 0
Views: 393
Reputation: 123453
e.currentTarget
appears to be what you're looking for:
links.on('click', function (e) {
alert(e.currentTarget.get('id'));
});
From NodeList's on
:
By default, the
this
object will be theNodeList
that the subscription came from, not theNode
that received the event. Usee.currentTarget
to refer to theNode
.
Upvotes: 1