I am trying to create a simple if statement: if .information-overlay has the CSS property display:block, add background-color:blue;; to body. If not, don't.
HTML:
<div class="information">Information</div>
<div class="work">Work</div>
<div class="information-overlay">INFORMATION OVERLAY</div>
<div class="work-overlay">WORK OVERLAY</div>
CSS:
.information-overlay, .work-overlay {
display:none;
width: 300px;
height: 300px;
background-color: salmon;
}
JS:
$('.information').click(function () {
$('.information-overlay').fadeToggle();
$('.work-overlay').fadeOut();
if ($('.information-overlay').css('display') == 'block') {
$('body').css('backgroundColor', 'blue');
}
if ($('.information-overlay').css('display') == 'none') {
$('body').css('backgroundColor', 'white');
}
});
This works fine, however it does not set the body back to background-color: white; when the toggle fades out (or is call the second if again). It is stuck on blue. Does anyone know how to fix this?
Here is a JSFIDDLE: http://jsfiddle.net/hWXeM/6/