Walks up the DOM tree until a non-empty computed style value is found.
Starting element, or null to return undefined.
null
undefined
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.
element
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 Copy
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
getComputedStyle
Walks up the DOM tree until a non-empty computed style value is found.