Setting inline styles
To set the inline style of an element, you use the style
property of that element:
element.style
Code language: CSS (css)
The style
property returns the read-only CSSStyleDeclaration
object that contains a list of CSS properties. For example, to set the color of an element to red
, you use the following code:
element.style.color = 'red';
Code language: JavaScript (javascript)
If the CSS property contains hyphens (-
) for example -webkit-text-stroke
you can use the array-like notation ([]
) to access the property:
element.style.['-webkit-text-stock'] = 'unset';
Code language: JavaScript (javascript)