Reputation: 11888
Here is my code :
<div id="foo" (click)="$event.target.classList.toggle('selected')">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
I would like to toggle the class 'selected' on the div#foo
thus $event.target
isn't correct since clicking one of the inside divs will return that div and not div#foo
. Any idea how to always target div#foo
when clicking on one of the element inside ?
Upvotes: 0
Views: 253
Reputation: 37413
use the currentTarget
instead of target
<div id="foo" (click)="$event.currentTarget.classList.toggle('selected')">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
Upvotes: 1