below is my simple code to change the background image of header tag but it is not working at the moment
$(window).scroll(function() {
if ($(this).scrollTop() > 400) {
$("header").css("background", "url(http://www.kreativestudio.ca/wp-content/themes/parasponsive/images/header_bg2.png) repeat-x scroll 0px rgba(0, 0, 0, 0) !important");
}
else {
console.log('there');
$("header").css("background", "url(http://www.kreativestudio.ca/wp-content/themes/parasponsive/images/header_bg.png) repeat-x scroll 0px rgba(0, 0, 0, 0) !important");
}
});
whats the matter in this code?
Remove !important from your jquery statement.
It’s not necessary because its an inline style and jquery css can’t handle it correctly.
If however you need it to be important, check out this question:
How to apply !important using .css()?
the problem is in the applied CSS, in background-image you’re only allowed to define the background image, “background” is the deal for you, try this (I also changed the code slightly but that’s just a matter of taste ;)):
FIDDLE