elena nincevic
elena nincevic

Reputation: 83

Change Part of URL String of an image

I am wondering if there is a way to change the last part (name of image) in a URL string using jQuery.

Here is what I have:

http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg

and here us what /i need it to be:

http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/140.jpg

Question update:

I need to target and replace the name of the image only, which is "80" in this case, without using the rest of the URL, as the URL path will be different for each image.

<div class="image">
<img alt="" src="http://thumbs3.ebaystatic.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg" itemprop="image">
</div>

Upvotes: 0

Views: 114

Answers (2)

elena nincevic
elena nincevic

Reputation: 83

OK, I found out the solution. If looking for the same thing, here it is:

$('.image').children().each(function () {
    $(this).html(function (i, html) {
        return $(this).html().replace(/80.jpg/g, '140.jpg');
    });
});

credit goes to @Eliseu Monar

Thank you!

Upvotes: 0

dm4web
dm4web

Reputation: 4652

replace

var s='http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg';

s=s.replace(/(.*)\/.*(\.jpg$)/i, '$1/40$2')

alert(s);

FIDDLE

Upvotes: 3

Related Questions