简体   繁体   中英

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/

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);

您拼写错误的“文档”,而写了“ documrnt”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM