Looks like we posted at the exact same time! :]

Correcting myself again: you should really use the regex, as the
simple string replace is case-sensitive.

On Feb 11, 5:40 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote:
> That's a simple Regular Expression (present in most programming
> languages, not just JS) that does a case-insensitive (/i) for '.png'
> at the end ($) of the string.
>
> See 
> here:https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Regular_Ex...
>
> You might want to filter the img elements first, depending on how many
> of those you have it could improve performance (better to test it).
>
> $("img[src$=.png]").each(...
> and then use a simple string replace: .replace('.png', '.jpg'); //is
> there any real chance of having ".png" in the middle of the filename?
>
> cheers,
> - ricardo
>
> On Feb 11, 5:29 pm, -e-train <etrai...@gmail.com> wrote:
>
> > Thanks James,
>
> > this seems to work well.
>
> > on the replace section, can you explain what this is doing?
>
> > /.png$/i,
>
> > i am not a javascript coder. it works, but i would like
> > to understand what is going on.
>
> > cheers.
> > -e-
>
> > On Feb 10, 6:14 pm, James <james.gp....@gmail.com> wrote:
>
> > > Un-tested, but maybe something like this:
>
> > > if ($.browser.msie && $.browser.version == '6.0') {
> > >      $("img").each(function() {
> > >           var new_src = $(this).attr("src").replace(/.png$/i, '.jpg');
> > >           $(this).attr("src", new_src);
> > >      });
>
> > > }
>
> > > Note that $.browser is deprecated from jQuery 1.3, but still available
> > > for use.
>
> > > On Feb 10, 3:26 pm, -e-train <etrai...@gmail.com> wrote:
>
> > > > Hi All,
>
> > > > I am new to jQuery and am having a hard time figuring out what i am
> > > > looking for in the docs an don this forum.
>
> > > > What i want to do is create a little jquery script that checks to see
> > > > if the browser is msie and browser.version is 6.0
>
> > > > I have that part done:
>
> > > > jQuery.each(jQuery.browser, function(i, val) {
> > > >         if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0") {
> > > >                 }
> > > >         }
>
> > > > });
>
> > > > I was able to display an alert. cool.
>
> > > > now what I would like to do is if the above is true and the agent is
> > > > msie 6.0
>
> > > > then i want to find all <img> tags that have a src="some-image.png"
> > > > and replace the ".png" with ".jpg"
>
> > > > i think i need to use the [attribute$=value] selector.
> > > > and then write something that is the equivalent of
> > > > if ("img[source$='png']")
> > > > then replace ("img[source$='png']") with ("img[source$='jpg']")
>
> > > > but i don't know how to write javascript very well...
>
> > > > any help is appreciated.
> > > > cheers,
> > > > -e-

Reply via email to