<!DOCTYPE html>
<html>
<head>
<script>
position=0;
var tLight = ["red light.gif","red_and_amber_light.gif","green light.gif","amber light.gif"]
function changeImage() {
if (position==0) {
document.getElementById('myImage').innerHTML=tLight[1]
position=1;
}
else if (position==1) {
document.getElementById('myImage').innerHTML=tLight[2]
position=2;
}
else if (position==2) {
document.getElementById('myImage').innerHTML=tLight[3]
position=3;
}
else if (position==3) {
document.getElementById('myImage').innerHTML=tLight[4]
position=4;
}
}
</script>
</head>
<body>
<img id="myImage" src="red light.gif" width="100" height="180">
<button type="button"
onclick="changeImage()">click for da lite</button>
</body>
</html>
I cant seem to find the problem in this code and i don't know whether it is me being blind or.....? someone please help. I have looked at the chrome "Developer Tools" but this cant detect any issues.
innerHTMLof an image ,doesn't change the src attribute ?setAttributefunction instead ofinnerHTML