paphonb
paphonb

Reputation: 83

Polymer 1.0 on-tap event's target is child

I'm using on-tap to detect element clicks.

<div id="parent" on-tap="myclickEvent">
    <h1>Some text<h1>
</div>

But when i click on it, the target attribute in the fired event is the h1. How do I change to make the parent element be the target?

Upvotes: 3

Views: 3358

Answers (2)

Fareed Alnamrouti
Fareed Alnamrouti

Reputation: 32154

here is very useful notes you should take care of:

  • make sure your element has a unique id (this is very important)
  • if your element inside the template use event.currentTarget
  • if your element inside the content (shady DOM or shadow DOM) use Polymer.dom(event).rootTarget

Upvotes: 2

Neil John Ramal
Neil John Ramal

Reputation: 3734

Try e.currentTarget. Don't expect it to be shown in console.log though as that browser function is asynchronous in Chrome (actually don't even bother logging event objects or objects inside events). But you can see it actually returns a div if you try this in your code.

myclickEvent: function(e){
  ...
  var tag = e.currentTarget.tagName;
  console.log(tag);
}

Upvotes: 9

Related Questions