I found in one of the topics and saved the code in index.html, but for some reason it does not work. I have 3 pictures: note.png, note_30.png, note_30_.png, I corrected the code in accordance with these pictures. A picture of note.png appears on the screen. But the click does not occur, the picture does not change. All pictures are in the same folder as the index. What have I done wrong?
Here is the code:
<html> <head> <title>Смена картинок</title> <script language="javascript"> var i=0; var image=document.getElementById("image"); var imgs=new Array('note.png','note_30.png', 'note_30_.png'); // Добавте свои картинки через запятую function imgsrc(){ i++; image.src=imgs[i]; } </script> </head> <body> <img id="image" src="note.png" onClick="imgsrc();"> </body> </html> To see the script in action, uploaded it to a temporary host: http://melody.a-workshop.ru/index.html
var image=document.getElementById("image");already working out .... you need to initialize it after downloading the content ....window.onloadfor example orDOMContentLoadedlearn.javascript.ru/onload-ondomcontentloaded - Aleksey Shimanskyiand the length of the array ..... and nullify at height .... by the way, I drew this in answer - Alexey Shimansky