James123
James123

Reputation: 11652

find and replace image url source?

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?

Upvotes: 0

Views: 2207

Answers (4)

Ortiga
Ortiga

Reputation: 8814

$('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();
});

Upvotes: 1

Shavit Cohen
Shavit Cohen

Reputation: 98

You can also use the parent class :

$('td.ms-vb img').attr('src','');

Upvotes: 0

andyb
andyb

Reputation: 43823

$('img').each(function() {
    $(this).attr('src', '');
});

will empty all src. You can change the first selector to suit your needs.

Upvotes: 2

George Cummins
George Cummins

Reputation: 28906

$( "img[src='/_layouts/images/square.gif']" ).attr( 'src', '' );

Upvotes: 1

Related Questions