
previous

page 10
next
but ... there's so much more ...
Easier to show you than explain.
In the following I'm going to make many deliberate mistakes so please copy and paste where possible.
Keeping it simple, I'm going to add to our project so that when we click on the picture, it changes. So you'll need another image.
Now replace your image element with:
<img src="pic1.jpg" id='img1' onClick='change(this);'>
I've omitted the alt attribute for simplicity.
Now reload your page and click on the picture. Note that nothing happens!
But check out the JavaScript Console!
So create a new file, my.js with this in it and try again.
function change(image) {
g_n++;
if (g_n=3) g_n=1;
image.src='pic'+g_n+'.jpg';
}
g_n++;
if (g_n=3) g_n=1;
image.src='pic'+g_n+'.jpg';
}
previous
next