Function: setCssVariable()
ts
function setCssVariable(
key,
val,
ele?): void;Sets a CSS variable on the specified element or the root element.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The name of the CSS variable to set. |
val | string | The value to set the CSS variable to. |
ele? | HTMLElement | The element to set the CSS variable on. If not specified, defaults to the root element. |
Returns
void
Example
ts
// Set a CSS variable on the root element
setCssVariable('--main-bg-color', '#ffffff');
// Set a CSS variable on a specific element
const element = document.querySelector('.my-element');
setCssVariable('--main-bg-color', '#ffffff', element)Since
1.0.0