Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  145] [ 4]  / answers: 1 / hits: 67746  / 15 Years ago, fri, march 26, 2010, 12:00:00

I have a full path to an image, which I am using jQuery to read like this:



$('img.my_image').attr('src');


However I just want the filename portion (i.e. without full path).



Are there any built-in functions to do this, or would a regex be the only option?


More From » jquery

 Answers
23
var fileNameIndex = yourstring.lastIndexOf(/) + 1;
var filename = yourstring.substr(fileNameIndex);

[#97228] Wednesday, March 24, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kelsy

Total Points: 486
Total Questions: 86
Total Answers: 76

Location: El Salvador
Member since Sun, Sep 12, 2021
3 Years ago
kelsy questions
Tue, Oct 19, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Wed, Jun 17, 20, 00:00, 4 Years ago
Fri, Jan 10, 20, 00:00, 4 Years ago
;