CLiown
CLiown

Reputation: 13853

jQuery - Alter URL on Click

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?

Upvotes: 0

Views: 208

Answers (2)

Benubird
Benubird

Reputation: 19557

Yes, use replace() function.

newImgSrc = newImgSrc.replace(/_s\.jpg/,'.jpg');

Upvotes: 1

Radek
Radek

Reputation: 8386

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

Upvotes: 0

Related Questions