changing the background color of the page - (document.bgcolor)

by Sanju 2010-02-05 08:46:29

The easiest way to change the background color of a page is using the property bgcolor.

document.bgColor="green";

Example: Code
<script language=javascript>
document.write("<input type=button value=red onclick=bgc()>");
function bgc(){
alert("sdsd");
document.bgColor="#e1FFE1";
}
</script>



But note that you have to set the color to the proper element. If there are elements like table which are above the document with color set on it, this wont work.

Then you will have to use something like

document.getElementById('<element id>').bgColor="green";


Tagged in:

1347
like
0
dislike
0
mail
flag

You must LOGIN to add comments