Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 970
manidos Avatar asked Sep 05 '25 16:09

manidos


1 Answers

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

or

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

See also Change an element's class with JavaScript

like image 122
Günter Zöchbauer Avatar answered Sep 07 '25 17:09

Günter Zöchbauer