Different Current Target Using On-tap On Paper-button With Iron-icons
Why current target on-tap is different using paper-button with iron-icons and paper-button without iron-icons?
Solution 1:
If you want to access the paper-button
when its contents are clicked, use the Event.currentTarget
(instead of target
):
Identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to
event.target
which identifies the element on which the event occurred.
For example:
_onTap: function(e) {
console.log('currentTarget:', e.currentTarget);
}
HTMLImports.whenReady(() => {
Polymer({
is: 'x-foo',
_onTap: function(e) {
console.log('tap currentTarget:', e.currentTarget);
}
});
});
<head><basehref="https://polygit.org/polymer+1.7.1/components/"><scriptsrc="webcomponentsjs/webcomponents-lite.min.js"></script><linkhref="polymer/polymer.html"><linkhref="paper-button/paper-button.html"><linkhref="paper-icon-button/paper-icon-button.html"><linkhref="iron-icon/iron-icon.html"><linkhref="iron-icons/iron-icons.html"><linkhref="iron-icons/communication-icons.html"></head><body><x-foo></x-foo><dom-moduleid="x-foo"><template><div>paper-button:</div><paper-buttonon-tap="_onTap"><iron-iconicon="communication:email"></iron-icon>
Email
</paper-button><div><div>paper-icon-button:</div><paper-icon-buttonicon="communication:email"on-tap="_onTap"></paper-icon-button></div></template></dom-module></body>
Post a Comment for "Different Current Target Using On-tap On Paper-button With Iron-icons"