Search code examples
javascriptgetcomputedstyle

How to get border-width using ComputedStyle in Javascript?


The following command

window.getComputedStyle(box).getPropertyValue("border")

is returning

"0.994318px solid rgb(255, 0, 0)"

How do I get border-width using ComputerStyle? Is there a way to replace the "border" argument by other one so it would, in the above case, output

0.994318px

Solution

  • Similar to Why won't .getPropertyValue() return a value for the "borderRadius" property?

    Specify the exact CSS property you want, so 'border-width'

    Edit: As @HereticMonkey pointed out (which I missed in the linked post), in Firefox, you need to get very granular with your property. So in the case of border-width, you need to get the exact border, e.g. border-bottom-width.