find and replace image url source?
-
28-10-2019 - |
Question
I have an image without class
and id
, just src
exists. I want to empty the src
attribute.
<td class="ms-vb" style="padding-bottom: 5px;">
<img alt="" src="/_layouts/images/square.gif"/>
<td>
to
<td class="ms-vb" style="padding-bottom: 5px;">
<img alt="" src=""/>
</td>
I need to find this image among several images in HTML. How to do that?
Solution
$('img[src="/_layouts/images/square.gif"]').each(function(){
$(this).attr("src","");
});
Anyway, @kingjiv is right, is better for you to remove it entirely:
$('img[src="/_layouts/images/square.gif"]').each(function(){
$(this).remove();
});
OTHER TIPS
$('img').each(function() {
$(this).attr('src', '');
});
will empty all src
. You can change the first selector to suit your needs.
$( "img[src='/_layouts/images/square.gif']" ).attr( 'src', '' );
You can also use the parent class :
$('td.ms-vb img').attr('src','');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow