We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

damarev on 07/06/07


Tagged

jquery


Versions (?)


Who likes this?

10 people have marked this snippet as a favorite

basicmagic
vvarp
penguin999
francisre
vali29
heinz1959
yetanother
martingoldszein
blackabee
korzhik


rollover images with Jquery


Published in: JavaScript 


  1. attachRollOverEvent = function(imageId){
  2. $(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").split('_off').join('_on')) } );
  3. $(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").split('_on').join('_off')) } );
  4. }
  5.  
  6.  
  7. $().ready(function(){
  8. attachRollOverEvent("#menu a img.roll");
  9. });

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: damarev on March 3, 2008

Correct. But if you want to define A LOT of images, this syntax is more compact and clear.

Posted By: eroteme on July 12, 2007

$("#menu a img.roll").hover(function(){$(this).attr("src", $(this).attr("src").split('off').join('on'))}, function(){$(this).attr("src", $(this).attr("src").split('on').join('off'))});

It can be shortened using the hover function.

You need to login to post a comment.