How to get border width in jQuery/javascript

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.

Leave a Comment