Skip to content Skip to sidebar Skip to footer

Change The Background Color And Text Color With A Timer With Javascript

I'm trying to change both the background and text color of a table and all its cells with a timer. I have the script below just before the end tag. The background is the only th

Solution 1:

(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 the above code inside a <script> element at the bottom of your page.

Solution 2:

var titleTable = document.getElementById('titleTable');

if(x==0 && set==1) -> if((x==0) && (set==1))

Just use "blink" tag =)

Ah, "The background is the only thing that changes". Check styles. If you have CSS rule like

#titleTabletd { color: black; }

It will not be overriden by setting inline style to the table.

Post a Comment for "Change The Background Color And Text Color With A Timer With Javascript"