0

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>

2 Answers 2

3

replace

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

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

alert(s);

FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.