<!DOCTYPE html> <html lang="ja-JP"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.5"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> $(function(){ var img = $("<img>").attr("src","img/after.png"); $("img").hover(function(){ $(this).attr("src",img.attr("src")).attr("alt","変更後"); },function(){ $(this).attr("src","img/before.png").attr("alt","変更前"); }); //下の記述でも可 /* var img = $("").attr("src","img/after.png"); $("img").mouseenter(function(){ $(this).attr("src",img.attr("src")).attr("alt","変更後"); }).mouseleave(function(){ $(this).attr("src","img/before.png").attr("alt","変更前"); }); */ }); </script> <style> img{ cursor:pointer; } </style> </head> <body> <img src="img/before.png" alt="変更前"> </body> </html>