To add style to an element in JavaScript, you can use the style
property of the element.
Here's an example:
index.tsx218 chars7 lines
In this example, we first get the element using document.getElementById()
. We then use the style
property of the element to add CSS properties like color
and border
.
This method of adding inline styles using JavaScript should be used sparingly and only when necessary. It's generally better to keep your styling in separate CSS files.
gistlibby LogSnag