Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  126] [ 3]  / answers: 1 / hits: 76400  / 14 Years ago, fri, september 24, 2010, 12:00:00

How do I parse the border width from



style=border: solid 1px black;



in jQuery/javascript?



$elem.css('border-width')



doesn't do it.



Note I need to parse the width from the css, as the element may be display:none



Thanks



Edit I'm not actually using an in-line style, I just wrote it that way for simplicity as I didn't realise there was any behavoural difference. It seems to work fine for inline styles though, but still can't get any value from an applied css class.


More From » jquery

 Answers
121

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.


[#95510] Wednesday, September 22, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sophiak

Total Points: 242
Total Questions: 90
Total Answers: 103

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;