This is the easiest way: Fiddle, and it uses this sprite sheet: https://i.stack.imgur.com/OWeVC.png
There are two ways to do this. The lightweight way is to use CSS, like so:
#mylink-1 {
background: transparent url('/img/my-img.png') 0 0 no-repeat;
}
#mylink-1:hover {
background: transparent url('/img/my-img-over.png') 0 0 no-repeat;
}
#mylink-2 {
background: transparent url('/img/my-img-2.png') 0 0 no-repeat;
}
#mylink-2:hover {
background: transparent url('/img/my-img-2-over.png') 0 0 no-repeat;
}
Or, using a sprite sheet:
#mylink-1 {
background: transparent url('/img/my-img.png') 0 0 no-repeat;
}
#mylink-1:hover {
background: transparent url('/img/my-img-over.png') 0 -20px no-repeat;
}
The second way is JavaScript. If you're using jQuery:
$('#mylink-1').on('hover', function() {
$(this).css({ background: 'transparent url("/img/my-img-over.png") 0 0 no-repeat' });
});
If you have lots of them, and name the images with numbers or use sprites, you can do something like this:
var i = 1;
// Non-sprite
#('.mylinks').each(function() {
$(this).css({ background: "transparent url('/img/my-img-' + i +'-over.png') 0 0 no-repeat" });
i++;
});
var i = 0;
// Using sprites
#('.mylinks').each(function() {
$(this).css({ background: "transparent url('/img/my-img-over.png') 0 ' + i + 'px no-repeat" });
i -= 20;
});