How to get border width in jQuery/javascript

后端 未结 5 604
南方客
南方客 2020-11-30 07:12

How do I parse the border width from

style=\"border: solid 1px black;\"

in jQuery/javascript?

$elem.css(\'border-width\')<

5条回答
  •  天命终不由人
    2020-11-30 07:50

    You can just use parseInt(); to parse the border width from Npx to N:

    var width = $elem.css('borderWidth'); // 150px
    var parsed = parseInt(width);         // 150
    

    I had a Google around and it appears in order to get the width of a border you must provide an explicit side of the border:

    var borderWidth = $elem.css("border-left-width");
    

    This is because it's possible for every border to have a different size, style and colour. Unfortunately it doesn't appear to be any simpler than this.

提交回复
热议问题