Skip to content

Function: getStyleProps()

ts
function getStyleProps(element, propName?): string | StyleProps;

Get the style properties of an element.

Parameters

ParameterTypeDescription
elementHTMLElementThe element to get the style properties of.
propName?stringThe name of the property to get.

Returns

string | StyleProps

If propName is specified, returns the value of that property. Otherwise, returns an object containing all style properties and their values.

Example

ts
const element = document.createElement('div')
element.style.color = 'red'
document.body.appendChild(element)
console.log(getStyleProps(element, 'color'))

Since

1.0.0

Released under the MIT License.