< Buzzing or vibrating the login form using jquery Posted On May 15, 2012 : 0 comments << >> Simple div slideshow using jquery Posted On May 9, 2012 : 0 comments << >> Copy mysql column in varchar to type date Posted On May 3, 2012 : 0 comments << >> Enter only numbers inside a input field of a form using javascript Posted On May 1, 2012 : 0 comments << >> Slide in and out animate div vertically using jquery Posted On April 25, 2012 : 1 comment << >> Tag cloud using php, mysql and ajax with filter Posted On April 24, 2012 : 0 comments << >> Change webpage font color or background color from the user side using javascript Posted On April 19, 2012 : 0 comments << >> A single link that cycles through several webpage background color using javascript Posted On April 17, 2012 : 0 comments << >> Simple webpage redirection using perl script Posted On April 10, 2012 : 0 comments << >> Get ipaddress using perl script Posted On April 4, 2012 : 0 comments << >>

Change webpage background color using javascript

This Tutorial Has Been Viewed 3,919 Times.
VN:F [1.9.17_1161]
Rating: 5.0/10 (8 votes cast)

Hello guys, i am back again with yet another simple but interesting tutorial of changing webpage background color using javascript, just copy and paste it to your webpage and customize it according to your webpage design.

<script language="javascript">
    function chngebg (id)
    {
        switch (id)
        {
            case 'b1':
                document.body.bgColor = "red";
                break;

            case 'b2':
                document.body.bgColor = "blue";
                break;

            case 'b3':
                document.body.bgColor = "black";
                break;    

            case 'b4':
                document.body.bgColor = "yellow";
                break;
        }
    }
</script>
<body>
<input type="button" id="b1" onclick="chngebg(this.id)" value="Red"/>
<input type="button" id="b2" onclick="chngebg(this.id)" value="Blue"/>
<input type="button" id="b3" onclick="chngebg(this.id)" value="Black"/>
<input type="button" id="b4" onclick="chngebg(this.id)" value="Yellow"/>
</body>

DEMO

VN:F [1.9.17_1161]
Rating: 5.0/10 (8 votes cast)

Change webpage background color using javascript, 5.0 out of 10 based on 8 ratings

Incoming search terms:





You will also be interested in ,

11 Responses

  1. Ben says:

    Hi, my friend showed me that you can use javascript to change things in your browser by doing stuff like javascript:”Hi” and that, but I forgot how to change the background color, not of your website, but turn your browser window into a solid color. Help, please?

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
    • admin says:

      You cannot change your browser color as far as i know, you can just change your web-page background.

      VN:F [1.9.17_1161]
      Rating: 0.0/5 (0 votes cast)
  2. I tried to copy this code in, but it didnt work. Thought it might have been due to css attachment so got rid of that but still not working, any suggestions?

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
    • admin says:

      Hello Alan,
      Thanks for your comment, Please check now, I have made the code much easier for copy paste.[Previously some extra character was popping up while copying and that might prevented the code from working, fixed it]
      Please let me know if you have any issues.

      VN:F [1.9.17_1161]
      Rating: 0.0/5 (0 votes cast)
  3. หางานหาดใหญ่ says:

    Nice information. I like it. Thank

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  4. Jump says:

    Hello, I find your article useful… However I also need to change the font color along with the background color & also I wonder if you can change the bg color for other div within the same page as well… Is there a way to do that? Thanks. :)

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
    • admin says:

      Hello,
      Thanks for your comment.
      Yes you can do that by using this attribute document.getElementById(‘YOUR DIV NAME’).style.backgroundColor = “YOUR COLOR”

      VN:F [1.9.17_1161]
      Rating: 0.0/5 (0 votes cast)
  5. Takashi says:

    Thank you for this tutorial.

    How would this be done by having only one link that cycles through several background colours?

    Thanks!
    Takashi

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)
  6. frank pepper says:

    i have done web development long ago, but now have a friend who is color blind, and i am wondering if there is any way to change colors/text from the user side

    thankx

    VA:F [1.9.17_1161]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks