You can do it in many ways, I can think of at least 6 different ways but I am giving you only one of them as an example:
- javascript code
$(document).ready(function() {
// attaching onclick event listener to all images with class swappable
$('img.swappable').click(function() {
// get current event target
var $this = $(this);
// get current src value and store it in swap variable (local scope)
var swap = $this.attr('src');
// set src's new value to the value of rel=""
$this.attr('src', $this.attr('rel'));
// set rel's value to the old src value
$this.attr('rel', swap);
});
});
- html code
<img src="your/non_hover/image/address" rel="your/hover/image/address" class="swappable" />
Note: The code is well formatted for readability but can be optimized for fewer calls and minified.