Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Onclick function image 1 - image 2


ghost's Avatar
0 0

I want it so when the user clicks the image it changes to a differant image.

I'm now sure how to do this though, I was thinking something along the lines of..

<img src="abc.gif" onclick=src="efg.gif";

or whatever idk.


ghost's Avatar
0 0

<img src="abc.gif" OnClick="this.src='efg.gif'">

Seems like something that you could have quite easily googled though ;).


ghost's Avatar
0 0

i thought som1 would say that nah i looked and looked coudltn find it thanks dude


ghost's Avatar
0 0

okay you need to do it with id's

&lt;script&gt;
function update()
{
document.getElementById(&quot;img&quot;).value=&quot;img2.jpg&quot;;
}

&lt;/script&gt;

&lt;img id=&quot;img&quot; src=&quot;img1.jpg&quot; /&gt;


ghost's Avatar
0 0

Only_samurai are u sure i need to acces value ? Wouldn't it be supposed to be document.getElementById("image").src="new image.jpg"; No offence. and for the changing image i would do this

<script type='text/javascript'> function Mouseover() { document.getElementById("img").src="new image.jpg"; } function Mouseout() { document.getElementById("img").src="old image.jpg"; } </script> <img src='old image.jpg' alt='' onMouseover='Mouseover()' onMouseout='Mouseout()'>

Ok hope that helps u.


ghost's Avatar
0 0

doh, yes… src. not value.

he doesnt have to use get elementbyid tho, its a choice for w/e you wanna use.