Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should be able to switch images as many times as you wish.</p> <p>The piece of code you reference replaces the image source of #target, with the href of a link within a #thumbs div. It should work fine.</p> <pre><code>&lt;img id="target" src="images/main.jpg"&gt; &lt;div id="thumbs"&gt; &lt;a href="images/picture1_big.jpg"&gt;&lt;img src="images/picture1_small.jpg"&gt;&lt;/a&gt; &lt;a href="images/picture2_big.jpg"&gt;&lt;img src="images/picture2_small.jpg"&gt;&lt;/a&gt; &lt;a href="images/picture3_big.jpg"&gt;&lt;img src="images/picture3_small.jpg"&gt;&lt;/a&gt; &lt;/div&gt; </code></pre> <p>Now as far as width and height, I am pretty sure there are some cross-browser compatibility issues with how browsers handle a defined width, but an undefined height, when you swap out the images.</p> <p>In firefox, the following works. Plain old javascript, no jquery:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function swap(image) { document.getElementById("main").src = image.href; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img id="main" src="images/main.jpg" width="50"&gt; &lt;a href="images/picture1_big.jpg" onclick="swap(this); return false;"&gt;&lt;img src="images/picture1_small.jpg"&gt;&lt;/a&gt; &lt;a href="images/picture2_big.jpg" onclick="swap(this); return false;"&gt;&lt;img src="images/picture2_small.jpg"&gt;&lt;/a&gt; &lt;a href="images/picture3_big.jpg" onclick="swap(this); return false;"&gt;&lt;img src="images/picture3_small.jpg"&gt;&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload