I want to do the follow, if a user hover on a link that the image will swap with a image with '-on' at the end.
But how can i get the swap thing on the image when i hover the a tag?
HTML code:
<div>
<a href="#">
<img src="image.jpg" alt="" />
Here some caption
</a>
</div>
I can not place the image urls in the header...
$(function () {
$('a img').hover( function () {
$(this).attr('src', $(this).attr('src').replace(/\.jpg/, '-on.jpg') );
});
});
Read the jQuery docs on replace
and attr
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With