How do I add a style class in TypeScript?
To add a class to an element in TypeScript:
- Select the element.
- Use the classList. add() method to add a class to the element.
- The method adds the provided class to the element if it isn’t already present.
- // getting the target element. var myElement = document. querySelector(‘#myElement’);
- // example for addding some-class to the element. myElement. classList. add(‘some-class’);
- // multiple classes can be added like this. myElement. classList.
className and classList. Changing a class is one of the most often used actions in scripts.
It sets the color of the element’s text to red.
– Inline CSS – Internal CSS – External CSS