jquery - change image src with .replace -
i've got images want change image when hover on div. image 1: "geluid1", image 2: "geluid2".
$(".block").mouseover(function(){ $("img",this).attr("src").replace("1","2"); }); but reason doesn't seem work properly. can me find problem?
your code src of image , replaced content. however, did not updated src attribute of img.
you didn't set src attribute value of img. use following code set src value replaced one.
$("img",this).attr("src", $('img', this).attr('src').replace("1","2")); code
$(".block").mouseover(function() { var img = $('img', this); // cache image object img.attr('src', img.attr('src').replace('1', '2')); // update image src url new url });
Comments
Post a Comment