Attempts to get the specified style property with name key from the specified target. If the value is found, it is coerced to a boolean if "true" or "false", a number if numeric, or the string value if a string. If not found, returns undefined.
key
target
"true"
"false"
undefined
Type of value to return.
Element, EventTarget, or CSS selector.
Name of the style property to get.
Value of type T or undefined if not found.
T
elements!InvalidElementError if the target could not be found or doesn't have a style property.
elements!InvalidElementError
HTML
<div id="example" style="display: flex; line-height: 1.5;">...</div> Copy
<div id="example" style="display: flex; line-height: 1.5;">...</div>
Code
const element = findElement("#example")!;getStyle(element, "display");// "flex"getStyle(element, "lineHeight");// 1.5 Copy
const element = findElement("#example")!;getStyle(element, "display");// "flex"getStyle(element, "lineHeight");// 1.5
Attempts to get the specified style property with name
key
from the specifiedtarget
. If the value is found, it is coerced to a boolean if"true"
or"false"
, a number if numeric, or the string value if a string. If not found, returnsundefined
.