manidos
manidos

Reputation: 3464

Change class of another element using template reference variable

I have this component template:

<div id="one" (click)=""></div>
<div id="two" #two></div>

What should I put inside (click)="" to assign the second div some class. I know it can be done inside component code, but is there a way to do it directly in template?

Upvotes: 4

Views: 3031

Answers (2)

Yogesh Aggarwal
Yogesh Aggarwal

Reputation: 1115

<div id="one" (click)="document.getElementById('#two').classList.add('soemClass')"></div>
<div id="two" #two></div>

This may help you!

Upvotes: -1

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657308

(click)="two.className = 'someClass'"

or

(click)="two.classList.add('someClass')"

See also Change an element's class with JavaScript

Upvotes: 4

Related Questions