JQuery.css () does not return the color border set to red

CSS: .divIm { border:1px solid red; } .divIm { border:1px solid red; } , and the line of code var borderColor = $(this).css("border-color") returns "" . What's wrong? Or would it be correct to try to get a computed style if I use jQuery?

Update: The following is code that does not want to work as expected.

 $("div.divIm").mouseover(function() { var borderColor = $(this).css("border-color"); debugger; }); 
+7
jquery css
source share
3 answers

Since each of the four borders can have a different color, .css('border-color') cannot work, which color to return (even if they are all the same).

In most cases, the color of all borders is the same, so you can do this as follows:

 $('div.divIm').mouseover(function() { var borderColor = $(this).css('border-left-color'); debugger; }); 

So, you get the color of the left border, and this should be enough for your needs.

+10
source share

You can get a computed style with curStyles jQuery Plugin , including several computed styles.

+2
source share
 var borderColor = $(this).css("border-color") 

You need to show more than that. But if that’s all you have, the problem is that this not defined.

 var borderColor = $('.divIm').css("border-color"); 

Will be what you need.

-one
source share

All Articles