You can use the bubbles. From your handler, you can look at event.target
to see if A
was pressed, and if so, skip the action.
Be careful because event.target
may be SPAN
! You need to not only check if the event target is an A
tag, but also go to the DOM tree in a simple bubble simulation.
So this is a possible solution:
template
(click)="doSomething($event)"
component
export class AppComponent { content = '<a href="http://google.com">Link text <span>Nested text</span></a>' doSomething(e) { let target = e.target; while (target !== e.currentTarget) { if (target.tagName == 'A') return; target = target.parentNode; } alert('do something') } }
Plunger example
source share