Reputation: 6251
If I have a list of items in my template, like this:
<template name="myTemplate">
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</template>
And my event handler looks something like this:
Template.myTemplate.events({
'click li': function(event) {
console.log(event.currentTarget//.? .html, .value?
}
});
How would I access the value of the li item that was clicked? i.e. I want to access 'One' or 'Two', etc. I tried .html and .value, which would have been the jquery-esque way to do it. My understanding is using 'currentTarget' is correct, since 'target' should match all li's, but I don't know how to hone in on the html value.
Upvotes: 1
Views: 602
Reputation: 2457
You can try this :
Template.myTemplate.events({
'click li': function(event) {
$(event.target).html()
//console.log(event.currentTarget//.? .html, .value?
}
});
Upvotes: 1
Reputation: 817
As anonymous say. use the native attribute innerHTML to get the content of a DOM element. otherwise Meteor come with JQuery so you can use it like this
console.log($(event.currentTarget).html());
Upvotes: 1
Reputation: 6251
.innerHTML is the answer.
console.log(event.currentTarget.innerHTML); // Outputs li HTML content
Upvotes: 2