html - Change the background color and text color with a timer with Javascript -
i'm trying change both background , text color of table , cells timer. have script below before end tag. background thing changes. id of table 'titletable'. thanks
<script language="javascript"> <!-- begin titletable.bgcolor='#ffffff'; setinterval("timer()", 500); x=1; function timer() { set=1; if(x==0 && set==1) { titletable.bgcolor='#000000'; titletable.style.color='#ffffff'; x=1; set=0; } if(x==1 && set==1) { titletable.bgcolor='#ffffff'; titletable.style.color='#000000'; x=0; set=0; } } // end --> </script>
(function() { var s = document.getelementbyid('titletable').style, f = false, c1 = '#000000', c2 = '#ffffff'; setinterval(function() { s.backgroundcolor = f ? c1 : c2; s.color = f ? c2 : c1; f = !f; }, 500); })();
live demo: http://jsfiddle.net/dzk2h/2/
just put above code inside <script>
element @ bottom of page.
Comments
Post a Comment