I have some confusions, I want to put hover on image <img>
tag without using "background-image". So that when user try to mouseover, the image will be change.
How can i do this?
Thanks.
<img src="a.jpg" onmouseover="this.src='b.jpg'" onmouseout="this.src='a.jpg'" />
this
refer to the current img
tag
a.logo {
display:block;
width: 100px;
height: 100px;
background: url(/path/to/logo.png) no-repeat center center;
background-size: contain;
}
a.logo:hover {
background-image: url(/path/to/logo-hover.png);
}
<a href="#" class="logo"></a>
By using css, you get more flexibility and it will work even on JavaScript-Disabled environments.
Useful on advanced situations
var img = document.getElementById('myImg');
img.onmouseout = function () {
this.src = 'b.jpg';
};
img.onmouseover = function () {
this.src = 'a.jpg';
};
Inline version: <img src="original.jpg" onmouseover="this.src='hover.jpg';" onmouseout="this.src='original.jpg';" />
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