I am trying to change the img src on hover with JQuery. I am using Brackets, and when I run a live Chrome preview its all good. But when I open the file directly on Chrome it doesn't work (same with IE).
My code:
$("#logo img").hover(
function(){
$("#logo img").attr("src","/images/img1.gif");
}, function() {
$("#logo img").attr("src","/images/img2.gif");
});
Edit: This is the HTML code:
<div id="logo">
<img id="logo-img" src="images/img1.gif" alt="logo">
</div>
The img tag has an id "logo-img", but using this id directly doesn't help:
$("#logo-img").hover(
function(){
$("#logo-img").attr("src","/images/img1.gif");
}, function() {
$("#logo-img").attr("src","/images/img2.gif");
});
Your help is appreciated.