Search code examples
javascriptjqueryjquery-selectorsdom-traversal

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?


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