Published in: JavaScript
attachRollOverEvent = function(imageId){ $(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").split('_off').join('_on')) } ); $(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").split('_on').join('_off')) } ); } $().ready(function(){ attachRollOverEvent("#menu a img.roll"); });
Comments
Subscribe to comments
You need to login to post a comment.

Correct. But if you want to define A LOT of images, this syntax is more compact and clear.
$("#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.