This module provides functions for querying and manipulating the style property on HTML and SVG elements.

Type Aliases

StyleKey

Valid style keys (i.e. non-methods) that can be set on an element.

Styles

Object representing element styles with a key of StyleKey and a value of StyleValue.

StylesSearch

Search criteria for checking if style properties are present in an element. You can use an array of style property names to check only if the styles are present, or an object to search for specific values. Use null for the value if you only care about the presence of a style property.

StyleValue

Value that can be set for an element style. The value is stringified prior to being set on the element.

Functions

getStyle

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.

getStyles

Builds an object with the keys equal to the specified keys and the value equal to the corresponding style property value in 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, the value is excluded from the return value.

hasAllStyles

Checks if all of the style properties on the specified target match the specified search criteria.

hasSomeStyles

Checks if some of the style properties on the specified target match the specified search criteria.

hasStyle

Checks if the specified target has the specified style property with name key. If a value is specified, checks that the values match.

removeStyle

Removes the specified style key from the specified target.

removeStyles

Removes the style properties with names matching the specified keys from the specified target.

setStyle

Sets the style property with name key to the specified value on the specified target.

setStyles

Sets the style properties of the specified target to the specified styles object with key of style property name and value of the corresponding property value.