I found many scripts about changing color of background, for example this one:
function changeBGC(color){
document.bgColor = color;
}
My current HTML is:
<a href="#" onMouseOver="javascript:changeBGC('#000099')">Mouseover Blue</a>
It seems it's working only with a white background at the beginning, because if I set some color with CSS like:
body {
background-color: #000000;
}
then its not working anymore.
If you want to change the background color of body then use the following code:
function changeBGC(color){
document.body.style.backgroundColor = color;
}
This will change the color of background.
Change the background-color
style instead of using the outdated bgColor
:
function changeBGC(color) {
document.body.style.backgroundColor = color;
}
Note: document
does not have a style property - see user Kolink's comment.
<a id="test" ...> ... </a>
use jquery:
$("#test").hover(function(){
$(this).css("background","color");
},function(){
$(this).css("background","#000");
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.