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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -