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');
Not just for
top
, it is also applicable forright
,left
, andbottom
.This is also a non-working code :
Since
border
,margin
,padding
properties of CSS is seperately editable. Ifborder-top
is different thanborder-left
, browser may be confused which it must return when you just askedborder
.Try this:
FIDDLE
Perhaps you are trying to use multiple properties use the following syntax
$('img').css({'border':'solid 2px red','color':'green'})
the shorthand property not supported in Jquery.
Quoting
.css
docs.For the case of
border
, you need to use theborder-width
,border-style
andborder-color
related properties.e.g.
border-color
:Supported properties in firefox:
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
to get the string like "
2px solid rgb(255,255,255)'