How to set image src to empty? [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
src is not empty but points to current url
if I remove
never let me to assign it back in the future
What’s the best way to accomplish this?
I’d just access the underlaying
<img> node and set the value of
src to an empty string.
$('#img')[ 0 ].src="#";
Update: It seems like Chrome is not satisfied when we just pass in an empty string. Firefox still shows the expected behavior (I’m pretty sure that this also worked in Chrome a couple of weeks/versions ago).
However, passing over a
# for instance, works fine.
imgNode.removeAttribute('src'); does no longer remove the visual representation of an image anymore in Chrome (interesting…).
The attribute ‘src’ isn’t really a property, it is an attribute. Think of properties as things that can be set with booleans or lists and attributes as things that are much more dynamic.
As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes – http://api.jquery.com/prop/