Like Haim Evgi suggested, you could get the CSS value of the element, but if you try this
console.log(jQuery('#someId').css('background-color'));
on an element without any background-color
set, you'll get transparent
.
Now let's say you want to expand your usecase to not only cover #f00
but a variable color, you could get into trouble.
My first idea, while reading your question was to use CSS classes to identify changes:
CSS
/* i assume red indicates an error :) */
.error { background-color: #f00; }
JavaScript
if(jQuery('#someId').hasClass('error')) {
/* do something fancy */
}
or
jQuery.each(jQuery('.error'), function(index, value) {
/* do something with each erroneous element */
});
This makes it also slightly more comfortable to set and check changes.
[Edit: a sample snippet]
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.error{ background-color: #f00; }
</style>
<script type="text/javascript" language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
console.log('Background #someId: ' + jQuery('#someId').css('background-color')); // transparent
console.log('Background #someOtherId: ' + jQuery('#someOtherId').css('background-color')); // transparent
console.log('#someId has error: ' + jQuery('#someId').hasClass('error')); // false
console.log('#someOtherId has error: ' + jQuery('#someOtherId').hasClass('error')); // false
jQuery('#someOtherId').addClass('error');
console.log('#someId has error: ' + jQuery('#someId').hasClass('error')); // false
console.log('#someOtherId has error: ' + jQuery('#someOtherId').hasClass('error')); // true
});
</script>
</head>
<body>
<div id="someId">foo</div>
<div id="someOtherId">bar</div>
</body>
</html>