Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuous div background color changer 1

Status
Not open for further replies.
The line that specifies that the document's color be changed is [tt]document.bgcolor = color[/tt]

Change document to what you want.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
OK, thank you, but I'm not sure what syntax to use:

document.divname.bgcolor

or

divname.bgcolor

??
 
document.getElementById("divname").bgcolor

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Thank you, but I'm still having a problem

Code:
<body>
<script language="JavaScript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - [URL unfurl="true"]http://www.javascript-page.com[/URL]

var currentcolor = 0

function initArray(n) {
  this.length = n;
  for (var i =1; i <= n; i++) {
    this[i] = ' '
  }
}

bgcolors = new initArray(15)
bgcolors[0]="ffffff"
bgcolors[1]="ffdead"
bgcolors[2]="ffffff"
bgcolors[3]="add8e6"
bgcolors[4]="0000ff"
bgcolors[5]="add8e6"
bgcolors[6]="90ee90"
bgcolors[7]="00ff00"
bgcolors[8]="90ee90"
bgcolors[9]="ffc0cb"
bgcolors[10]="ff0000"
bgcolors[11]="ffc0cb"
bgcolors[12]="FFFFFF"
bgcolors[13]="ffdead"
bgcolors[14]="FFFFFF"

function backgroundChanger() {
[COLOR=red]document.getElementById("test").bgcolor[/color] = bgcolors[currentcolor];

if (currentcolor < bgcolors.length-1) {
currentcolor++
setTimeout("backgroundChanger()", 1000);
}
}

backgroundChanger();
//-->
</script>


<div id="test" style="width: 400px; height: 200px"></div>
</body>

I don't know what's wrong
 
for IE:
document.all["test"].style.backgroundColor

for NS:
document.layers["test"].bgColor



--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Also, the function backgroundChanger should be called in the body tag using <body onLoad="backgroundChanger()"> or the script should be placed after the div.

Otherwise, the function will try to change the div before it exists.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top