Hi
I am having problems with the following code, for some reason the function is only affecting the first <div id="txt"> tag and not the other two. I know by changing each div tag id and running the function 3 times it works. Any help would be appreciated.
Thank you
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
div.red {
color:red;
}
div.blue{
color:blue;
}
</style>
<script type="text/javascript">
function switchColor(elem,one,two) {
theClass = document.getElementById(elem).className;
if(theClass == one) {
document.getElementById(elem).className = two;
} else {
document.getElementById(elem).className = one;
}
}
doit = setInterval("switchColor('txt','red','blue')",500);
</script>
</head>
<body>
<div id="txt">Test 1</div>
<div id="txt">Test 2</div>
<div id="txt">Test 3</div>
</body>
</html>
I am having problems with the following code, for some reason the function is only affecting the first <div id="txt"> tag and not the other two. I know by changing each div tag id and running the function 3 times it works. Any help would be appreciated.
Thank you
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
div.red {
color:red;
}
div.blue{
color:blue;
}
</style>
<script type="text/javascript">
function switchColor(elem,one,two) {
theClass = document.getElementById(elem).className;
if(theClass == one) {
document.getElementById(elem).className = two;
} else {
document.getElementById(elem).className = one;
}
}
doit = setInterval("switchColor('txt','red','blue')",500);
</script>
</head>
<body>
<div id="txt">Test 1</div>
<div id="txt">Test 2</div>
<div id="txt">Test 3</div>
</body>
</html>