user1957109
user1957109

Reputation:

Image change on hover

Hi, I have a HTML image that is setup like this:

<input id="img" type="image" src="">

How can I change src on hover?

.

Upvotes: 1

Views: 167

Answers (3)

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

use jQuery for this tag

<input id="img1" type="image" src="">

$("#img1").hover(function() {
  $(this).addClass("blue");
}, function() {
  $(this).removeClass("blue");
});

in css class you can write src for this input image tag.

Upvotes: 0

Davit
Davit

Reputation: 1375

Try this:

<script type="text/javascript">
$(document).ready(function(){
   $("#img").hover(function(){
      $(this).attr("src","img1.jpg");
   },function(){
      $(this).attr("src","img2.jpg");
   });
});
</script>
<input id="img" type="image" src="">

Upvotes: 3

William Buttlicker
William Buttlicker

Reputation: 6000

Expecting an item to be hovered on i suggest this:

   $('.item').mouseover(function (e) {
    var id = $(this).val();
    $("#img").attr("src",id);
  });

Upvotes: 0

Related Questions