I want to change the background color and text color of an element in my header when the menu is visible. I want to achieve a continuous menu look. however, i also want the element to go back to it's original style when the menu is hidden. However, my jQuery code does not work. There are no syntax errors but it still doesn't work. I have the code in an if statement. Here's the link to the jsFiddle
http://jsfiddle.net/kamvkg14/2/
Here's the code responsible for the style change
if ($('.account-menu').css('display') != 'none') {
$('.header_account').css({
'background-color': 'white',
'padding-bottom': '16px',
'color': 'black'
});
} else {
$('.header_account').css({
'background-color': 'yellow',
'padding-bottom': '0px',
'color': '#00FFFF'
});
}
ifstatement gets evaluated only once when the page is loaded – it doesn’t magically react to any changes in the menu’s display status later on. You would have put that into your function that changes the menu state. But ideally, you should not manipulate CSS values directly, but simple add/remove a class to the element that takes care of the different formatting.header_account, I introduced one – and then implemented what I said, by toggling an additional class on that element: jsfiddle.net/kamvkg14/5