+ 5
How to change the background color of the page using JavaScript?
I was just thinking of a project of background changer!! In it I tried to design a code in which the background is directly changed by clicking a button!! But for that I will have to link it to JavaScript, but for the background color, it's the CSS part!! How to I directly change the background color of the page using JavaScript.
2 odpowiedzi
+ 5
Try this:
<button class="whatever" onclick="document.body.style.backgroundColor = 'red'">click to change BG color</button>
+ 3
var button = document.getElementById("whatever");
button.onclick = function(){
document.body.style.backgroundColor = "whatever-you-choose";
};