@jossmac/lil-libs
    Preparing search index...

    Function nearestComputedStyle

    • Walks up the DOM tree until a non-empty computed style value is found.

      • element: HTMLElement | SVGElement | null

        Starting element, or null to return undefined.

      • name: string

        CSS property or custom property name (same format as getComputedStyle).

      The first non-empty computed value on element or an ancestor; undefined when element is null or no ancestor has a value.

      const parent = document.createElement("div");
      parent.style.color = "rgb(255, 0, 0)";
      const child = document.createElement("span");
      parent.appendChild(child);

      nearestComputedStyle(child, "color"); // "rgb(255, 0, 0)" (inherited from parent)
      nearestComputedStyle(null, "color"); // undefined