RosAng
RosAng

Reputation: 1040

Polymer 1.0 How to get the id of the clicked paper button?

I have a set of paper buttons like below:

<div><paper-button  id="100" on-tap="addQuantity">100ML</paper-button><paper-button toggles id="200" on-click="addQuantity">200ML</paper-button><paper-button toggles id="300" on-click="addQuantity">300ML</paper-button></div>
And i want to know the id of each button when clicked. I tried like this in Javascript function. It does not work

addQuantity:function(e)
		{
			console.log(e.target.id);
			
		}

How to solve this?

Upvotes: 3

Views: 2038

Answers (3)

Lio
Lio

Reputation: 29

To get the clicked element id:

addQuantity:function(e) {
    var target = e.currentTarget;
    var id = target.id;
}

Upvotes: 3

Justin XL
Justin XL

Reputation: 39006

Try this -

addQuantity: function (e) {
    var button = Polymer.dom(e).localTarget;
    console.log(button.id);
}

Upvotes: 5

Zikes
Zikes

Reputation: 5886

Try using e.srcElement.id instead.

Upvotes: 1

Related Questions