Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  111] [ 1]  / answers: 1 / hits: 65184  / 12 Years ago, wed, december 5, 2012, 12:00:00

Possible Duplicate:

Setting image src attribute not working in Chrome






When user clicks on remove link I need to set the src attribute of an image to empty. When I do it using



$('#img').prop('src', null);


src is not empty but points to current url



if I remove src using



$('#img').removeProp('src');


never let me to assign it back in the future



What's the best way to accomplish this?


More From » jquery

 Answers
20

Try using attr(),



Live Demo



$('#img').attr('src', '');


As you have id selector. Using the native javascript method document.getElementById will give you more performance benefit. Also you may need to set # as src instead of empty string.



document.getElementById('img').src = #;

[#81602] Tuesday, December 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaidyn

Total Points: 633
Total Questions: 102
Total Answers: 100

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;