Velija daviiii Velija daviiii - 2 months ago 5
Javascript Question

javascript Change page background color with button

I am trying to figure out how to do code for changing the background color of a page with a button

so basically I have the code for a button written out and its function but im having trouble figuring out what code to use to make the button change the color of the entire page

<script>
function changeColor()
{

};
function changeText()
{
alert ("change text in this part");
};
function sendMsg()
{
alert ("change msg content here");
}
</script>




<body>
<h1>Welcome to my program!</h1>
<button onclick="changeColor()">Color</button>
<button onclick="changeText()">Text</button> </br>
<p>Can I ask you something Ive always wanted to ask the real Batman?</p> </br>
<input type="text" name="">
</body>

Answer
  document.body.style.background = color;

There's not much more to it, it's as simple as that!

Comments