IE and css via use of jquery

Go To


I would like to set a css properties like this


for example, but instead I write


and nothing is done on IE. what is wrong with that ? The former works whilst the latter fails..

2012-04-04 06:25
by Cafebabee


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.


var cafe = '#482610';
$('#something').css('color', cafe);
2012-04-11 06:23
by Tarun


cafe isn't a valid hex color..

try #FFFFFF for example or #CCCCCC

2012-04-04 06:28
by Ramon
Yes, sorry I was wrong about that - Cafebabee 2012-04-04 06:32


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.

2012-04-04 06:28
by Greg Pettit
Yes, I should have added two more 00 at the end of of cafe :- - Cafebabee 2012-04-04 06:31
>cafe00 is quite a nice chartreuse. ;-) - Greg Pettit 2012-04-04 06:33


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 :

2012-04-04 06:30
by m90
Well spotted with the selector - Greg Pettit 2012-04-04 06:34


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 :)

2012-04-04 06:31
by Andreas Wong