how to get the the value of background-color property
if ($(this).css('background-color') == 'InfoBackground')
{
// it doesn't enter here
}
how to get the the value of background-color property
if ($(this).css('background-color') == 'InfoBackground')
{
// it doesn't enter here
}
background color outputs are rgb()
in jQuery as far as I know, so I don't think if there's a convenient way of comparing it!
take a look at THIS example,
alert($('#color').css('background-color'));
if($('#color').css('background-color')=='red'){
alert('first if');
}
it will not enter the first if because $('#color').css('background-color')
equals rgb(255,0,0)
and it doesn't match red
so it wont get inside the if condition.
what you can do, is to give the desired DOM a class, and check if the element has the class, like this:
if($('#color').hasClass('red')){
alert('second if');
}
which will fire the alert inside of it.
You'll want to check against the RGB value of whatever InfoBackground
is.
Notice the following returns rgb(251, 252, 197)
if ($("#myElement").css('background-color') == 'rgb(251, 252, 197)') {
alert('hello');
}
#myElement { background-color: InfoBackground; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="myElement">Hi</div>
However, this seems like kind of a fickle approach. Different browsers might behave differently or implement InfoBackground
differently. It would be better to assign a class, property, or data-attribute and then use that to dictate the color.