0% found this document useful (0 votes)
199 views

Javascript - How To Change Css Style in Typescript - Stack Overflow

The document discusses how to change CSS styles in TypeScript. It provides two examples of how to do this: 1) Get the element with the class name, assert it as an HTML collection, check if it has a length, and set the style transform property. 2) Get the element with the class name and directly set its style transform property. Both examples show how to select the element and set its style transform property programmatically in TypeScript.

Uploaded by

Ilhan Kalač
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views

Javascript - How To Change Css Style in Typescript - Stack Overflow

The document discusses how to change CSS styles in TypeScript. It provides two examples of how to do this: 1) Get the element with the class name, assert it as an HTML collection, check if it has a length, and set the style transform property. 2) Get the element with the class name and directly set its style transform property. Both examples show how to select the element and set its style transform property programmatically in TypeScript.

Uploaded by

Ilhan Kalač
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like