tags:

views:

127

answers:

2

Using $("#id").css("background-color") to retrieve an element's background color (or most other CSS attributes) works just fine, but $("#id").css("border-color") returns an empty string.

How can I get the border color value used on the element?

+3  A: 

CSS has "short-hand" properties that allows you to send multiple properties at once. Like font, border, background, etc. Well the border-color CSS property actually sets the 4 properties border-top-color, border-right-color, border-bottom-color, and border-left-color.

If you want to get the border-color, you need to specify which side. For instance, border-left-color $("#id").css("border-left-color"). This should work just fine since it seems as you're expecting that every side has the same color.

William
Sounds logical, but it also returns empty string (null with chrome).
JussiR
Sorry, I wrote it wrong. It's border-left-color, border-top-color, border-right-color, border-bottom color. I will update my answer.
William
I just realize Gausie already posted the solution below.
William
Yep, that works.
JussiR
+2  A: 

William was close... The property you're looking for is border-left-color, so in full you need

$('#ID').css("border-left-color")

and to set it

$('#ID').css("border-left-color","blue");

for example.

Good luck, and hit me back in the comments.

Gausie
Great! I think we have the answer, thanks for everone envolved!
JussiR
Thanks for the correct Gausie, I must be out of it today.
William
No problem. It's your solution really - could you mark his Accepted JussiR?
Gausie
Oh, right. I thought there was a feature to mark accepted answers, but only now realised how to do that.
JussiR