1

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>
Velija daviiii
  • 15
  • 1
  • 2
  • 5
  • You can get answer on internet via search engine: http://stackoverflow.com/questions/197748/how-do-i-change-the-background-color-with-javascript – Rong Nguyen Apr 05 '13 at 01:38
  • thank you so much ive been searching for 45 minutes and every search has brought me how to change the color of a button and not the background – Velija daviiii Apr 05 '13 at 01:47

2 Answers2

1
  document.body.style.background = color;

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

What have you tried
  • 11,018
  • 4
  • 31
  • 45
  • thanks very much, I had that code before but every time I tried it wouldnt execute properly, i finally figured it out tho thank you. – Velija daviiii Apr 05 '13 at 01:47
-2

Try out this code my dear :

<FORM> 
<INPUT type="button" value="Change to Yellow!" name="button3" onClick="document.bgColor='yellow'"> <br> 
<INPUT type="button" value="Change to Red!" name="button4" onClick="document.bgColor='red'"> <br> 
<INPUT type="button" value="Change back!" name="button5" onClick="document.bgColor='white'"> </FORM>
AlexVogel
  • 10,601
  • 10
  • 61
  • 71