 <p>It will be pretty straight forward with jQuery. Below Fiddle will help you.</p> <p><a href="http://jsfiddle.net/17g6q8k0/2/" rel="nofollow">http://jsfiddle.net/17g6q8k0/2/</a></p> <pre><code>var sourceSwap = function () { var $this = $(this); var newSource = $this.data('alt-src'); $this.data('alt-src', $this.attr('src')); $this.attr('src', newSource); } $(function() { $('img[data-alt-src]').each(function() { new Image().src = $(this).data('alt-src'); }).hover(sourceSwap, sourceSwap); }); </code></pre>