0

I have a small custom made thumbnail gallery. On click of a thumbnail I want to get the bigger version of the image. To do this I am getting the img's src. With that I want to replace a certain section of the string for another string. For example the thumbnail's source may look like this:

/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg

I need to replace width_60_ with width_104_. Is this possible with Javascript?

JAAulde
19.5k5 gold badges57 silver badges65 bronze badges
asked Oct 14, 2011 at 15:21
2
  • @JAAulde, SO should replace Google for such. Otherwise, vote it down, vote to close, provide an answer, a relevant comment... but snotty remarks are not needed. Commented Oct 14, 2011 at 15:38
  • @Sparky672 I voted it down and provided a comment about why...standard SO procedure... Commented Oct 14, 2011 at 15:39

1 Answer 1

7

Simply use the JS replace() function:

var imgSrc = "/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg"
var newSrc = imgSrc.replace("width_60_", "width_104_");

Here's a working jsFiddle.

answered Oct 14, 2011 at 15:23
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.