• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Div onClick Change Two Other Div Image Paths

Hi Experts,

Thanks for reading. I'm looking for a quick script that, onClick of a <div>, it changes the image path in another div and the other image path in another div. As a sample:

<div id="switchImagePaths"></div>

<div id="image1"><img src="pathChangesOnClickOnswitchImagePathsDiv.png" /></div>
<div id="image2"><img src="pathChangesOnClickOnswitchImagePathsDiv.png" /></div>

Open in new window


Thank you!
0
SevenAteAnthony
Asked:
SevenAteAnthony
1 Solution
 
leakim971PluritechnicianCommented:
Put this in the head section :
<script>
window.onload = function() {
    document.getElementById("switchImagePaths").onclick = function() {
        document.getElementById("image1").getElementsByTagName("img")[0].src = "http://galerie.croisitour.com/G2-46286106507.jpg";
        document.getElementById("image2").getElementsByTagName("img")[0].src = "http://iocp.potomitan.info/diasporas/images/petites_antilles2.jpg";
    }
}
</script>

test page : http://jsfiddle.net/FbZKC/
0
 
SevenAteAnthonyAuthor Commented:
Thanks so much!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now