Ahmad Asjad
Ahmad Asjad

Reputation: 823

how to change color dynamically

I want to change my marquee color Here is Html code

<marquee><div id="thakan">Thakaan ka Ant, Shakti Turant!!</div></marquee>

And this is the javascript code

<script language="javascript" type="text/javascript">
var col=0;
function changeMarqueeColor()
{
    if(col==0)
    {
        //document.getElementById("p2").style.color="blue";
        documrnt.getElementById("thakan").style.color="yello";
        col=1;
    }
    else
    {
        documrnt.getElementById("thakan").style.color="blue";
        col=0;
    }

}
 b=setInterval("changeMarqueeColor();",500);
</script>

You can access this also by visiting this link : http://jsfiddle.net/W4tzf/

Upvotes: 1

Views: 13258

Answers (2)

sabof
sabof

Reputation: 8192

The code below works. As others have mentioned, you've misspelled document. Also the simplest way to achieve what you want is with setInterval, and unquoted function name.

var col=0;
function changeMarqueeColor() 
{
    if(col==0)
    {
        document.getElementById("thakan").style.color="red";
        col=1;
    }
    else
    {
        document.getElementById("thakan").style.color="blue";
        col=0;
    }
}
setInterval(changeMarqueeColor,500);

Upvotes: 6

Miguel Nascimento
Miguel Nascimento

Reputation: 53

You misspelled "document", you wrote "documrnt" instead.

Upvotes: 3

Related Questions