PDA

View Full Version : Javascript - switch DIV content


l0rdQuas
02-18-2009, 11:12 PM
Hi

hopefully I can get the answer I need here, or any help with it will be much appriacted.

What I'm trying to do is switch the content of a div on the click of an image [button] the div in question holds the images to a jQuery zoom function[class="zoom"]. I'd like to change the images that are used on a button click.

heres a snippet of the code:

<div id="image">
<a href="images/image1.gif" class="zoom">
<img src="images/images1Large.gif"/>
</a>
</div>
<div id="button">
<img src="images/image1button.gif"/>
<img src="images/image2button.gif"/>
</div>

I'd like to be able to switch the (id)image div to contain:
<a href="images/image2.gif" class="zoom">
<img src="images/images2Large.gif"/>
</a>

onClick of img=image2button

Hope this makes sense, and thanks in advance for any help and suggestions

Cheers,

LQ

Eldarrion
02-26-2009, 07:00 PM
Here is the function you need to add to your javascript:

function imgclick() {
$("#image").html("<a href=\"images/image2.gif\" class=\"zoom\"><img src=\"images/images2Large.gif\"/></a>");
};


And of course


<img src="images/image2button.gif" onclick="imgclick()"/>


That should do the trick. Do let me know if it doesn't and I'll look into solving the problem.