To add multiple styles to an element in JavaScript, the style
property of the element can be manipulated. It is important to note that the CSS styles should be in camelCase format instead of hyphen-separated format.
Here's an example code snippet that demonstrates how to add multiple styles to an element:
35 chars2 lines
index.tsx146 chars5 lines
In the above code, we first grab the element using document.getElementById()
, and then we set various styles using the style
property. Each style is set by accessing a property of the style
object, using camelCase CSS property names.
So in summary, to add multiple styles to an element in JavaScript, we simply access the style
property of the element and set the desired styles as individual properties of that object.
gistlibby LogSnag