When I call window.getComputedStyle() on an element and try to get a property such as lineHeight, which can have both worded and numerical values, is there a way or a different function that will return a numerical value every time?
My line-height example refers to the normal keyword. Other examples include font weights and border widths. All these use keywords but map to numerical values.
If you are referring to the fact that the return value can contain
pxor other units, you can use theparseIntfunction:Here's a fiddle. Instead of returning
100pxit returns100You can extract the units like so:
fiddle
Edit:
Apparently,
normalcan be set to a "reasonable" value by the user agent, and is font-specific, where the spec recommends it be between 1.0 and 1.2. So you would probably be better off calculating it'sheightproperty.Here's an in depth blog post about it.