Click to See Complete Forum and Search --> : how do I change CSS classes or table background images w/ a script?


sez666
04-22-2003, 05:06 PM
I need to change the background image of a table cell automatically every couple of seconds, sliding thru several images... I need a script that changes either the table cell's background image or CSS class without any user input.

Any help is much appreciated!

Sarah

pyro
04-22-2003, 05:12 PM
To change a class: document.getElementById("someId").style.className="someclass";

To change the background document.getElementById("someId").style.background="your.gif";

Jona
04-22-2003, 05:15 PM
<html><head>
<script>
var a = setTimeout("change1()",1000);
function change1(){document.myTD.style.backgroundImage="file2.jpg"; clearTimeout(a); a = setTimeout("change2()",1000);}
function change2(){document.myTD.style.backgroundImage="file3.jpg"; clearTimeout(a); a = setTimeout("resetall()",1000);}
function resetall(){document.myTD.style.backgroundImage="file1.jpg"; clearTimeout(a); a = setTimeout("change1()",1000);}
</script></head><body>
<table>
<tr><td background="file1.jpg" id="myTD"></td></tr>
</table></body>
</html>