I'm sure the code could be optimized a bit more. It's looking at every
image tag on the page, which might be slow depending on how many
images you have.

(/.png$/i) part is using regular expressions (regex, for short):
http://en.wikipedia.org/wiki/Regular_expression

The $-sign indicates to look for ".png" the end of a string.
The "i" indicates that it's case-insensitive (therefore .png or .PNG
will match)

I'm only a novice with regex, but it's quite an art in itself once you
see what it can do.

On Feb 11, 9:29 am, -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