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>
Incoming search terms:
- use jquery to change document background color dynamically (36)
- Change background color using JavaScript (20)
- changing bgcolor javascript using alert (15)
- how to change background color using javascript (14)
- Changing the Background Color of a Page using jQuery (12)
- change bgcolor using javascript (12)
- change web page background color (8)
- how to change the background color using javascript (7)
- background color using javascript (7)
- change browser color javascript (7)
- jquery change body background color (7)
- how to change web page background color using javascript (6)
- change body background color using javascript (6)
- changing background color using javascript (6)
- color using javascript (5)
- change web page background color javascript (5)
- how to change background color in javascript with one button (4)
- changing color using javascript (4)
- change background color with one button javascript (4)
- change background color using button in javascript (3)
- body background color change using javascript (3)
- change background color using javascript function (3)
- to include background color in web page in javascript (3)
- how to add background color in javascript using button (3)
- change background colour of one page with java (3)
- change background using javascript (3)
- how to change java script on website (3)
- hot to change website color with js (3)
- change color using javascript (3)
- javascript timer change background color (3)
- change website using javascript (3)
- how to change background of webpage using javascript (3)
- javascript change website color (3)
- background color dynamically change using java script (3)
- change webpage background (2)
- onclick background colour change using javascript (2)
- change web page javascript (2)
- rating a website using java script and jsp (2)
- full website color change javascript (2)
- change web page background using javascript (2)
You will also be interested in ,
- Get browser window size using javascript
- Suppress javascript errors on your webpage easily
- Changing the image by dynamically changing the image source using javascript
- Javascript Clock
- Passing variables from javascript to php
- Javascript setTimeout() Tricks
- Check whether the browser is Internet Explorer or not using javascript
- Write data to a page using javascript
- Beautiful Christmas countdown timer complete webpage with css download free
- Extracting URL parameters with Javascript


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?
You cannot change your browser color as far as i know, you can just change your web-page background.
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?
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.
Nice information. I like it. Thank
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.
Hello,
Thanks for your comment.
Yes you can do that by using this attribute document.getElementById(‘YOUR DIV NAME’).style.backgroundColor = “YOUR COLOR”
Thank you for this tutorial.
How would this be done by having only one link that cycles through several background colours?
Thanks!
Takashi
Just check our new tutorial
http://mistonline.in/wp/a-single-link-that-cycles-through-several-webpage-background-color-using-javascript/
I think it will solve your concern.
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
Hello Frank,
If that is the case check our New Tutorial Here, It will ask the users which color they need on the website. This should help