hi all,
i'd like to split an image's href tag like
<img src='/root/myimages/myPic.jpg'>
so that i'm getting just myPic.jpg
- whats the easiest way?
thx
hi all,
i'd like to split an image's href tag like
<img src='/root/myimages/myPic.jpg'>
so that i'm getting just myPic.jpg
- whats the easiest way?
thx
var src = document.getElementById("yourImgId").src;
src = src.replace(/(.*\/)?([^/]*)$/, "$2");
<img id="myImg" src='/root/myimages/myPic.jpg'>
var str = $('#myImg').attr('src');
var newStr = str.substring(str.lastIndexOf("/") + 1);
function getFileName(path) {
return path.match(/[-_\w]+[.][\w]+$/i)[0];
}
getFileName('http://www.example.com/images/blah.png'); // blah.png
This getFileName()
function is awesome because the first part of the regex looks like a guy with an eye patch.