Note that there are some explanatory texts on larger screens.

plurals
  1. PORWD Mobile Device Image Swap JavaScript
    text
    copied!<p>I am using a bit of JavaScript to do an image swap.</p> <p>Works great on desktop browsers, but not working on mobile/smaller devices.</p> <pre><code>&lt;p&gt;&lt;img id="ima" src="images/web_assets/image1.jpg" width="270px" /&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="#" onmouseover="showT( 'images/web_assets/image1.jpg' )"&gt;&lt;img src="images/web_assets/image1.jpg" width="84px" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="#" onmouseover="showT( 'images/web_assets/image2.jpg' )"&gt;&lt;img src="images/web_assets/image2.jpg" width="84px" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="#" onmouseover="showT( 'images/web_assets/image3.jpg' )"&gt;&lt;img src="images/web_assets/image3.jpg" width="84px" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;script type="text/javascript"&gt; // &lt;![CDATA[ function showT(image) { document.getElementById('ima').setAttribute('src', image) } // ]]&gt; &lt;/script&gt; </code></pre> <p>Any idea's how to make this work on all devices (i.e. desktop, ipads, iphones, other mobile devices)?</p> <p><strong>New Code:</strong></p> <pre><code>&lt;p&gt;&lt;img id="ima" src="images/web_assets/image1.jpg" width="270px" /&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="#" onClick="showT( 'images/web_assets/image1.jpg' )"&gt;&lt;img src="images/web_assets/image1.jpg" width="84px" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="#" onClick="showT( 'images/web_assets/image2.jpg' )"&gt;&lt;img src="images/web_assets/image2.jpg" width="84px" /&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="#" onClick="showT( 'images/web_assets/image3.jpg' )"&gt;&lt;img src="images/web_assets/image3.jpg" width="84px" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;script type="text/javascript"&gt; // &lt;![CDATA[ function showT(image) { document.getElementById('ima').setAttribute('src', image) } // ]]&gt; &lt;/script&gt; </code></pre> <p>But onclick, it shoots the page back upto the top of the browser?!?!</p>
 

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