0

I've grabbing the URL of a thumbnail when clicking on it and adding it to another image in the HTML:

$('#result .thumb').live('click', function() {
    var newImgSrc = this.src;
    $("#thumbnail").attr("src", newImgSrc);             
});

However I want to alter the URL that gets sent, it currently looks something like:

...com/4100/5412955054_45ce3a897e_s.jpg

I want to remove _s from the very end of the URL. Can I do this in jQuery or Javascript?

2 Answers 2

1

Yes, use replace() function.

newImgSrc = newImgSrc.replace(/_s\.jpg/,'.jpg');
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the answer, although I think it should be: newImgSrc = newImgSrc.replace(/_s\.jpg/,'.jpg'); - as the "_s" should be removed.
0

JavaScript's replace method + regex. Or slicing two last chars before dot and extension.

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.