0

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 ?

1 Answer 1

1

use the currentTarget instead of target

<div id="foo" (click)="$event.currentTarget.classList.toggle('selected')">
   <div>...</div>
   <div>...</div>
   <div>...</div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.