Simple jQuery image hover replacement


/ Published in: jQuery
Save to your folder(s)

Add a "rollover" class and hover="img/src-hover.jpg" to the image in question.


Copy this code and paste it in your HTML
  1. $(function() {
  2. $('.rollover').hover(function() {
  3. var currentImg = $(this).attr('src');
  4. $(this).attr('src', $(this).attr('hover'));
  5. $(this).attr('hover', currentImg);
  6. }, function() {
  7. var currentImg = $(this).attr('src');
  8. $(this).attr('src', $(this).attr('hover'));
  9. $(this).attr('hover', currentImg);
  10. });
  11. });

URL: http://www.selfcontained.us/2008/03/08/simple-jquery-image-rollover-script/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.