I need to blink between two colors:red and white.
I’ve found that after $targetcss('background-color','red'),
value of $targetcss('background-color') is not red,but rgb(255, 255, 255),
pay attention that there is a space between “,” and digit in firefox,
but there is no space in IE.
And my code is now :
if(existingBgColor != 'rgb(255, 255, 255)')
$target.css('background-color', 'rgb(255, 255, 255)');
else
$target.css('background-color', 'white');
Which works in firefox,but no for IE.
Of course I can change it to this to make it apply for IE:
if(existingBgColor != 'rgb(255, 255, 255)' && existingBgColor != 'rgb(255,255,255)')
$target.css('background-color', 'rgb(255, 255, 255)');
else
$target.css('background-color', 'white');
But what for a third browser?
Is there a standard solution for this?
You could simply trim out all the whitespace before testing:
edit: as argued in the comments: Hex values are cross browser, and very easy to use. But if you insist on rgb values, then the above code will help you sort out your issues. However. If you start writing stuff like
$myElm.css("background-color", "red");, you’re gonna get a whole new set of issues…