Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting image src attribute not working in Chrome

Tags:

I want to get the src of one image and set it as another's src when #btn is pressed:

jQuery("#btn").live("click", function() {     jQuery("#another_div")         .children("img")         .attr("src", jQuery(this).prev("img").attr("src"));     jQuery(this)         .prev("img")         .attr("src",""); }) 

I have also tried:

jQuery(this).prev('img').removeAttr("src"); 

It works fine in Firefox, IE7-9, and Safari.

Only in Chrome, the image is not removed even when the source changes (src="").

like image 987
user883749 Avatar asked Dec 08 '11 03:12

user883749


2 Answers

You could change it to

jQuery(this).attr("src", "data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="); 

maybe?

like image 103
Joseph Marikle Avatar answered Sep 23 '22 04:09

Joseph Marikle


Since in my case by doing this

$(this).attr("src",""); 

clearing the src attribute, but, image does not vanish. Hence I just set, img tag style attribute display to none, like this

$(this).attr("src","").css("display", "none"); 

It will hide the image. I hope, it will temporarily work for you.

like image 40
Er. Dj Avatar answered Sep 23 '22 04:09

Er. Dj