I have a problem using jQuery
to switch between images when hovering on and off. Here's the code snippet I'm working with:
HTML
<img class="commentImg" src="images/comments.png" data-swap="images/comment_hover.png" alt="">
jQuery
$(".commentImg").hover(function() {
var swap = $(this).attr("data-swap");
$(this).attr('src', swap);
},
function() {
var swap = $(this).attr("data-swap");
$(this).removeAttr(swap);
});
The issue is that while the mouseover
event works fine, the mouseout
event doesn't trigger as expected. Can anyone assist me in resolving this?