0

How can you change css with typescript?

I was working in javascript, and now I have switched to angular where typescript is used instead of javascript. I have problem with changing value of css properties with ts. I want for example to chage background color of div by pressing button. But when I type: name?.style.backgroundColor="green", i have error?( of course i did this before: name=document.getElementById("name"));

8th Nov 2022, 8:55 PM
Adilx01
1 ответ
+ 1
it seems like optional chaining in typescript is returning error for assignment operator '=' on DOM elements. try this: let name = document.getElementById('name') as HTMLElement; name?.style.setProperty('background-color', 'green')
8th Nov 2022, 9:30 PM
Bob_Li
Bob_Li - avatar