6

I'm unable to get the border width of an element. I tried the following but it shows empty results. Check http://jsfiddle.net/s7YAN/14/

$('div').css('borderWidth');
2

3 Answers 3

11

borderWidth is syntactic sugar for setting each border's width independently. You can't assume that every border's width is the same, so you need to ask for a specific border's width.

$("div").css("borderTopWidth");
Sign up to request clarification or add additional context in comments.

1 Comment

that's an entirely different problem :). you can't just set a border width without setting a color and a style. jsfiddle.net/s7YAN/18
6

For border-width, you need to specify the side of the border. borderWidth/border-width is a shortcut for all of the border-width's at once.

$( function() {
    alert($('div').css("border-top-width"));
});

http://jsfiddle.net/ZsSmp/

Also, you need to specify more than a border width for it to be valid. Just specifying a border-width does not make a border. It needs a color and style, too:

border: 2px solid black;

1 Comment

Interesting, because "border-width" works in Chrome and Safari 6 on the mac, but not in Firefox on the mac.
3

The problem is you don't define the border-style in your CSS, so it's default to none, whose width is 0px.

Also, you should specify which border (left, top) for border-width is just a shortcut for all borders.

1 Comment

the bit about border-style defaulting to none just solved my hair pulling moment: thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.