I run the following code in the Firebug console.
$('img').css('border', 'solid 2px red').css('border');
The red image borders appear, but it returns an empty string, why is this?
It works fine in Chrome and Safari developer tools.
Update: The jQuery docs say that shorthand properties are not supported when getting CSS values. However I have also tried the following with no luck in Firefox (All work in Chrome and Safari)
$('img').css('border-style', 'solid').css('border-style');
$('img').css('borderStyle', 'solid').css('borderStyle');
$('img').css('border', 'solid 2px green').css('borderStyle');
CSS Border Not Showing 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.
The border-style property sets the style of an element's four borders. This property can have from one to four values. Examples: border-style: dotted solid double dashed; top border is dotted.
The inset CSS property is a shorthand that corresponds to the top , right , bottom , and/or left properties. It has the same multi-value syntax of the margin shorthand.
Quoting .css
docs.
Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use:
$(elem).css('marginTop')
and$(elem).css('marginRight')
, and so on.
For the case of border
, you need to use the border-width
, border-style
and border-color
related properties.
e.g. border-color
:
$('img').css('border-top-color', 'red').css('borderTopColor');
$('img').css('border-right-color', 'red').css('borderRightColor');
$('img').css('border-bottom-color', 'red').css('borderBottomColor');
$('img').css('border-left-color', 'red').css('borderLeftColor');
Try this:
var border = $('img').css('border', '2px solid red')[0].style.border;
FIDDLE
Supported properties in firefox:
'border-top-color'
'border-right-color'
'border-bottom-color'
'border-left-color'
'border-top-width'
'border-right-width'
'border-bottom-width'
'border-left-width'
'border-top-style'
'border-right-style'
'border-bottom-style'
'border-left-style'
Are the supported longhands :) Cheers! Enjoy!!!
You can still use shorthand to set border in most cases.
If you are sure they are the same do something like
var borderString = $('img').css('border-top-width') + " "
+ $('img').css('border-top-style') + " "
+ $('img').css('border-top-color');
to get the string like "2px solid rgb(255,255,255)'
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