1/7/2021 javascript - How to change css style in typescript?
- Stack Overflow
How to change css style in typescript?
Asked 3 years, 3 months ago Active 3 years, 2 months ago Viewed 28k times
In typescript how to change css styling just as I would do this way?
4 $(".s-hand").css("transform", "translate(-50%, -100%) rotate(" + s*6 + "deg)");
or
var hourPointer = document.querySelector('.hour')
hourPointer.style[transform] = `rotate(${hour}deg)`;
Because I have no idea how to achieve that..
javascript css typescript
asked Sep 28 '17 at 13:01
user8626881
2 Answers Active Oldest Votes
It has to be done like this:
6 let shand = document.getElementsByClassName('s-hand') as HTMLCollectionOf<HTMLElement>;
if (shand.length != 0) {
shand[0].style.transform = "translate(-50%, -100%) rotate(" + s * 6 + "deg)";
}
https://stackoverflow.com/questions/46469853/how-to-change-css-style-in-typescript/46470579 1/2
1/7/2021 javascript - How to change css style in typescript? - Stack Overflow
answered Oct 30 '17 at 13:05
user8626881
you can do it with simple javascript as mentioned below:
0 document.getElementsByClassName('s-hand').style.transform = 'translate(-50%, -100%)
rotate(" + s*6 + "deg)';
for any query please comment
answered Sep 28 '17 at 13:37
Nishant Singh
361 4 16
I have an error that property style doesn't exist on type HTMLCollectionOf<Element> – user8626881 Sep 29 '17 at 6:37
@AnotherChris If This answer is not working, why did you accepted it? for me its not working. – Arijit Oct 28 '17 at 19:18
i have added my answer – user8626881 Oct 30 '17 at 13:05
https://stackoverflow.com/questions/46469853/how-to-change-css-style-in-typescript/46470579 2/2