Clear an IMG with jQuery

后端 未结 9 2013
广开言路
广开言路 2021-02-05 01:35

I\'m trying to remove the loaded image from a element, but clearing or removing the src doesn\'t do it. What to do?

HTML:

相关标签:
9条回答
  • 2021-02-05 02:37

    You would have to either remove the <img> element entirely or replace it with a different image (which could be a transparent gif).

    0 讨论(0)
  • 2021-02-05 02:37

    Instead of showing broken image while setting "src" to "#", There is a workaround, so you can set alt attribute to the desired text:

     $('#thumbnialPreviewImage').attr('src', '#');
     $('#thumbnialPreviewImage').attr('alt', 'Please Select Image');
    
    0 讨论(0)
  • 2021-02-05 02:38

    the best way is to replace image with another. i mean instead of cleaning the src, set a fake value like .attr('src','notting'); it'll load no image and the cached version of old image will be gone

    0 讨论(0)
提交回复
热议问题