please improve this code. If we click on image 2 link . image link 2 no work.i also use more then 2 images in this code.
<script>
function changeImage() {
var image = document.getElementById('myImage');
var img1 = document.getElementById('1');
var img2 = document.getElementById('2');
var img3 = document.getElementById('3');
if (img1.id == 1 ) {
image.src = "img/1.jpg";
}
else if (img2.id == 2) {
image.src = "img/2.jpg";
}
else if (img3.id == 3) {
image.src = "img/3.jpg";
}
else
{
image.src = "img/5.jpg";
}
}
</script>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()" src="img/0.jpg" width="180" height="180">
<table>
<tr>
<td > <a href="#" id="1" onclick="changeImage()"> Image1</a></td>
</tr>
<tr>
<td> <a href="#" id="2" onclick="changeImage()"> Image2</a></td>
</tr>
<tr>
<td> <a href="#" id="3" onclick="changeImage()"> Image3</a></td>
</tr>
</table>
please improve this code. If we click on image 2 link . image link 2 no work.i also use more then 2 images in this code.
Thanks advance.
</body>
</html>
id's need to begin with a letter, see w3.org/TR/html401/types.html#type-name