admin管理员组

文章数量:1394191

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>

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?

Share Improve this question asked Aug 6, 2015 at 22:17 RosAngRosAng 1,0502 gold badges19 silver badges43 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Try this -

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

To get the clicked element id:

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

Try using e.srcElement.id instead.

本文标签: javascriptPolymer 10 How to get the id of the clicked paper buttonStack Overflow