views:

31

answers:

2

Wonder how I could do the following wit jquery -

I have a url pointing to an image -> http://www.website.com/folder/folder2/image_current.jpg (this value is stored in a variable)

I have variable that holds the value -> new_image.jpg

How can I with jquery update the full url (held in the variable) from

http://www.website.com/folder/folder2/image_current.jpg

to

http://www.website.com/folder/folder2/new_image.jpg

??

+2  A: 

Try something like this:

var url = 'http://www.website.com/folder/folder2/image_current.jpg';
var new_image = 'new_image.jpg';

var new_url = url.replace(url.substring(url.lastIndexOf('/')+1), new_image);
Jacob Relkin
Cheers for that..
Niall Collins
A: 

Try this.

aularon