tags:

views:

24

answers:

2

Hi!

I'd like to change image type with jquery, for example:

<img width="250" height="61" alt="Stack Overflow" src="http://sstatic.net/so/img/logo.png"/&gt;

to

<a href="/"><img width="250" height="61" alt="Stack Overflow" src="http://sstatic.net/so/img/logo.gif"/&gt;&lt;/a&gt;

To change ".png: in ".gif" (in this case)

Thanks !

+2  A: 

This should work:

$('img').each(function()
{
    this.src = this.src.replace(/png$/, '.gif');
});
Greg
+1  A: 

Try this: (Assuming that all .png images have equivalent .gif images on the server)

$('img[src$=".png"]').each(function(img) { 
    img.attr('src', img.attr('src').replace(/\.png$/, '.gif'));
});
SLaks
I think he is trying to change images wrapped in links. the initial selector should be something like $('a img[src$=".png"]')
Chris Gutierrez
I think he just made a mistake when copying the source.
SLaks