How can i change image source on hover with only CSS
i tried but was able to find only answers with javascript.
this is my code:
<img src="">
i want to change image to 1.gif when user mouse hover it.
How can i change image source on hover with only CSS
i tried but was able to find only answers with javascript.
this is my code:
<img src="">
i want to change image to 1.gif when user mouse hover it.
you can target the image first. and then from there when user mouser over the image you can change src attribute
const img = document.getElementById('imgId');
img.addEventListener('mouserover', callback);
function callback(event) {
if (img.src=== '1.gif') {
img.src = '2.gif';
}
}
img.addEventListener("mouseout", anotherCallback);
function anotherCallback(event) {
if (img.src !== "1.gif") {
img.src = '1.gif';
}
}