Reputation: 13
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.
Upvotes: 1
Views: 315
Reputation: 1130
<a id="test" ...> ... </a>
use jquery:
$("#test").hover(function(){
$(this).css("background","color");
},function(){
$(this).css("background","#000");
});
Upvotes: 0
Reputation: 15603
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.
Upvotes: 4
Reputation: 66663
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.
Upvotes: 2