Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A way to do this is to clone all the <code>&lt;img&gt;</code> nodes you want, put them inside <code>&lt;div&gt;</code>s and then use CSS's <a href="https://developer.mozilla.org/en-US/docs/CSS/%3ahover" rel="nofollow"><code>:hover</code></a> to do the rest of the work for you. <a href="http://jsfiddle.net/BysCN/" rel="nofollow"><strong>example fiddle</strong></a>.<br> My code will work for as many <code>&lt;img&gt;</code>s as you like, anywhere in the document and does not require fixed sizes of parent nodes.<br> You may need to modify your CSS or the class names I've chosen if other styles aren't as you expected due to the changes to HTML structure by the JavaScript (see "Resulting HTML" below).</p> <pre><code>// JavaScript window.onload = function () { // when document has loaded, consider `window.addEventListener('load', /* code */, false);` in real world usage var elm = document.querySelectorAll('img.rollover'), // get all &lt;img&gt;s with class "rollover" i = elm.length, d; while (--i &gt;= 0) { // put each one and a clone into a &lt;div&gt; where it was d = elm[i].parentNode.insertBefore(document.createElement('div'), elm[i]); d.className = 'rollover'; elm[i].className = (' '+elm[i].className+' ') // set class' .replace(/ rollover /g, ' ') .slice(1, -1); d.appendChild(elm[i]); d.appendChild(elm[i].cloneNode()).className += ' rollover_big'; // I did clone here to save needing an extra variable elm[i].className += ' rollover_small'; } }; /* CSS */ div.rollover {position: relative; display: block;} /* relative to allow for abs. positioning of big image */ div.rollover img.rollover_small {width: 24px;} div.rollover img.rollover_big { /* position over small image*/ width: 48px; display: none; position: absolute; top: 0px; } div.rollover:hover img.rollover_small {visibility: hidden;} /* visibility to hold space*/ div.rollover:hover img.rollover_big {display: block;} /* show bigger node*/ &lt;!-- HTML --&gt; &lt;table&gt; &lt;tr&gt; &lt;td colspan=2&gt;&lt;a href="contactdetail.php"&gt;&lt;img src="http://womeninbiznetwork.com/wp-content/uploads/2011/07/logo-google.thumbnail.gif" class="rollover"/&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Here is text&lt;/td&gt; &lt;/tr&gt; &lt;!-- etc. --&gt; &lt;/table&gt; &lt;!-- Resulting HTML after load event --&gt; &lt;table&gt; &lt;tr&gt; &lt;td colspan=2&gt;&lt;a href="contactdetail.php"&gt; &lt;div class="rollover"&gt; &lt;img src="http://womeninbiznetwork.com/wp-content/uploads/2011/07/logo-google.thumbnail.gif" class="rollover_small"/&gt; &lt;img src="http://womeninbiznetwork.com/wp-content/uploads/2011/07/logo-google.thumbnail.gif" class="rollover_big"/&gt; &lt;/div&gt; &lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Here is text&lt;/td&gt; &lt;/tr&gt; &lt;!-- etc. --&gt; &lt;/table&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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