I would like to set a css properties like this
$(#something).css({'color':'red'});
for example, but instead I write
$(#something).css({'color':'#cafe'});
and nothing is done on IE. what is wrong with that ? The former works whilst the latter fails..
I think you want to use keywords instead of color, so that you can use it multiple places. For that you should have to store it in a variable and then when you applying CSS through jQuery use variable instead of color.
Example:
var cafe = '#482610';
$('#something').css('color', cafe);
try #FFFFFF for example or #CCCCCC
There's no such color string as #cafe
. That's all. Maybe cafe
without the hash symbol, I've never tried. :-)
If you mean it to be a hex value, Ramon has it right, though you can also use short versions (3 characters):
#caf
would work.
You still have to use valid color values (with #cafe
not being one - red
is ok though as it is a predefined color) like you would do in a stylesheet.
See this list of prefined colors you can use for that. If you don't want a predefined color use hex-format either with 3 or 6 digits like #ff0000
or #f00
or RGB-notation rgb(255,0,0)
(the examples being red in all cases). See the specs on that
Btw. usually you would have to wrap your jQuery-selector in '
s like :
$('#something').css({'color':'red'});
http://www.w3.org/TR/css3-color/#rgb-color
The spec says:
The format of an RGB value in hexadecimal notation is a ‘#’ immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example,
fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies
on the color depth of the display.
So you can't depend on invalid values such as #cafe
, some browsers might try to be forgiving by padding extra 0's but you really can't depend on it. So stick with the spec :)