I have a html page, with jquery loaded. It has no css at the moment.
It has a background image set as:
<body background="image1.gif">
I'm trying to change this to a color (say black) and back again to the image using onclick.
I've managed to set up the divs and all ok. For changing color to color I used:
jQuery('body').css('background-color','black');
on another page, but that doesn't work here because i want to go from image to color and b开发者_JAVA百科ack again.
So, how can I change the background image to a flat color and back again with jquery?
Use css and change the class instead:
The HTML:
<body class="image">
The CSS:
body.image{
background-image: url('image.gif');
}
body.colour{
background-color: black;
}
And for scripting:
$('body').addClass('colour').removeClass('image');
And back again:
$('body').addClass('image').removeClass('colour');
精彩评论