CSS: .divIm { border:1px solid red; }
, and code-line var borderColor = $(this).css("border-color")
returns ""
. What is wrong? Or would it be correct trying to get computed style if I use jQuery?
Update: Below is a code which doesn't want to work as it expected.
$("div.divIm").mouseover(function() {
var borderColor = $(this).css("border-color");
debugger;
});
If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.
Each side can be set individually using border-top-color , border-right-color , border-bottom-color , and border-left-color ; or using the writing mode-aware border-block-start-color , border-block-end-color , border-inline-start-color , and border-inline-end-color .
Since every of the four borders can have a different color, .css('border-color')
cannot work out, which color to return (even if they are all the same).
In most of the cases, the color of all borders is the same, so you can do it like this:
$('div.divIm').mouseover(function() {
var borderColor = $(this).css('border-left-color');
debugger;
});
So you get the color of the left border and that should be enough for your needs.
You can get the computed style with curStyles jQuery Plugin including multiple computed styles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With