I have used this code to get the img
src
attribute:
$('.listpic').attr('currentSrc');
The image url is: newyorkmodelhstn.jpg
. I have to remove tn
from this to get the original img src. How can I do this?
I have used this code to get the img
src
attribute:
$('.listpic').attr('currentSrc');
The image url is: newyorkmodelhstn.jpg
. I have to remove tn
from this to get the original img src. How can I do this?
first rename the string then access it:
var str="newyorkmodelhstn.jpg";
var find = 'tn.';
var re = new RegExp(find, 'g');
str = str.replace(re, '.');//use this to get the image
alert(str);
or you can do this:
var str="newyorkmodelhstn.jpg";
str = str.replace("tn.", '.');//use this to get the image
visit this thread for good explanation and understanding:here
It is simple, i add dot because a 'th' can be in a middle word
var str = 'newyorkmodelhstn.jpg';
var result = str.replace('tn.', '.');
You can try this..
var imgs=document.getElementsByClassName("listpic");
for(var i=0;i< imgs.length;i++)
{
var str=imgs[i].src;
var find='tn.';
var re=new RegExp(find,'g');
str=str.replace(re, '.');
var a = $("<a>").attr("href", str).attr("download", imgs[i].alt).appendTo("body");
a[0].click();
a.remove(); }