Reputation: 13843
Im using the src of an image, however im fetching the thumbnail image src and need to manipulate the src to get the fullsize image:
Jquery:
$(this).attr('src');
That gets me: http://local/images/_w/image_jpg.jpg
I need to replace: _w/
to get the fullsize image, how can i do this in jQuery?
Upvotes: 0
Views: 825
Reputation: 235
You need to replace _w
with the string that contains the size and then set attribute src
again.
$(this).attr('src', $(this).attr('src').replace('_w', '100x100'));
Upvotes: 0
Reputation: 13621
<a href="#" class="swap">Swap</a>
<img class="thumb" src="http://local/images/_w/image_jpg.jpg" />
$(document).ready(function(){
$(".swap").click(function(){
var src = $(".thumb").attr("src");
src = src.replace("/_w", "");
$(".thumb").attr("src", src);
alert($(".thumb").attr("src"));
});
});
Here is an example on jsFiddle
Upvotes: 0
Reputation: 35587
you can do this:
var newImg = $('#myId').attr('src').replace('_w/','');
$('#myId').attr('src', newImg);
Upvotes: 0
Reputation: 17640
like this
var og_source = $(this).attr('src');
var replacement_text = "_big"
$(this).attr('src',$og_source.replace('_w/',replacement_text));
Upvotes: 0
Reputation: 419
It's not a question of getting jQuery to do it, as Javascript already has a replace function built in.
var v = $(this).attr('src').replace('_w','whatever');
$(this).attr('src', v );
Upvotes: 0
Reputation: 14468
You can use one of javacripts excellent string manipulation functions like replace
:
var src_fullsize = $(this).attr('src').replace('/_w/','/');
Upvotes: 0
Reputation: 480
$(this).attr('src').replace("_w/", "");
This is assuming you want to just remove the _w/
part of the path. Otherwise replace the empty string with whatever you need.
Upvotes: 0
Reputation: 6184
Like this:
var temp $(this).attr('src');
var NewURL = temp.replace("_w/", "derp");
Upvotes: 0
Reputation: 47978
$('#fullImage').attr('src', $(this).attr('src').replace('_w/', '???'));
Upvotes: 6