@laserware/dominator
    Preparing search index...

    Function setCssVar

    • Sets the CSS variable name to value in the optionally specified target.

      If no target is specified, uses documentElement (i.e. :root).

      Type Parameters

      Parameters

      • name: `--${string}`

        Name of the CSS variable to set or update.

      • value: CssVarValue

        Value of the CSS variable.

      • Optionaltarget: null | Target = document.documentElement

        Optional Element, EventTarget, or CSS selector.

      Returns E

      Element representation of the specified target.

      InvalidCssVarError if the name is not a valid CssVarName.

      elements!InvalidElementError if the specified target wasn't found.

      HTML (Before)

      <style>
      :root {
      --color-fg: green;
      }
      </style>

      <button id="example" style="--color-bg: blue;">
      Example
      </button>

      Set in Element

      const element = findElement("#example")!;

      setCssVar("--color-bg", "red", element);

      Set in :root

      setCssVar("--color-fg", "blue");
      

      HTML (After)

      <style>
      :root {
      --color-fg: blue;
      }
      </style>

      <button id="example" style="--color-bg: red;">
      Example
      </button>