javascript - JQuery change image src on mouseover not working in IE7 and 8 -


i have set of images want source change on mouseover. code works fine in except ie 7 , 8 - when hover on image changes broken image link.

my code is:

$(".socialicon").each(function() {    $(this).find("img")         .mouseover(function() {              var src = $(this).attr("src").match(/[^\.]+/) + "hover.png";             $(this).attr("src", src);         })         .mouseout(function() {             var src = $(this).attr("src").replace("hover.png", ".png");             $(this).attr("src", src);         }); }); 

would know if there have change have work in ie 7 , 8?

you should debug on ie7&8 - value of $(this).attr("src") , src attribute has element after enter mouse on element? suppose, ie maybe returns absolute path image, "http://example.com/image.png" - in case regex not work.

why not calling

var src = $(this).attr("src").replace(".png", "hover.png"); 

instead of

var src = $(this).attr("src").match(/[^\.]+/) + "hover.png"; 

this more consistent regarding mouseout method.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -