Reputation: 279
In the new paper-button 1.0 how do we tell which button has been clicked on? In 0.5 you inspected the element passed to the function.
Upvotes: 0
Views: 313
Reputation: 341
Let's say you have two buttons like these.
<paper-button id="b1" class="clickable" on-click="buttonClick">
button1
</paper-button>
<paper-button id="b2" class="clickable" on-click="buttonClick">
button2
</paper-button>
Then you can use this function to determine which one was clicked.
buttonClick: function (e) {
for (var i = 0, max = e.path.length; i < max; i++) {
if (e.path[i].classList && e.path[i].classList.contains("clickable")) {
console.log("clicked button: " + e.path[i].id);
return;
}
}
}
EDIT
Better solution:
buttonClick: function (e) {
console.log("clicked button: " + e.currentTarget.id);
}
Upvotes: 1
Reputation: 279
Use getAttributes.
setFilter: function(e) {
var filter = e.currentTarget.getAttribute("filter");
console.log(filter);
var title = e.currentTarget.getAttribute("title");
console.log(this.obj_filters);
Works a treat
Upvotes: 2