I want to extract the file name with a path and its extension separately from the src image using jquery.
eg:
<img src="images/cat/kitty.gif" id="myimg" />
I need to get "images / cat / kitty" and ".gif" from the code above.
How can i do this?
Instead, you can use attr:
attr
$('#image_id').attr('src');
If you want to specify the name and extension separately, you can do:
var arr = $('#image_id').attr('src').split('.'); alert(arr[0]); // name alert(arr[1]); // extension
To extract only the file name:
var name = $('#myimg').attr("src"); var parts = name.split('/'); name = parts[parts.length-1];
. .split():
.split()
var ret = $('#myimg').attr('src').split(/\./); console.log(ret[0]); // === 'images/cat/kitty' console.log(ret[1]); // === 'gif'
, '.' -
http://website.com/app/folder/imagemanager.php../../../user_images/2982034/images/image.png
, , jQuery, -
// Get the source var image_src = $(el).attr('src'); // Get the extension. As mentioned above, using split() and pop() var extension = image_src.split('.').pop(); // Get just the path. Replace the extension with '' var path = image_src.replace('.'+extension,'');
Source: https://habr.com/ru/post/1794073/More articles:Каков наилучший способ обработки "поиска" в REST API? Как насчет Сфинкса? - restXSD - Elements in any order and quantity (XML verified by XERCES using XSD) - xmlAndroid - problem with SurfaceView (width, height) - androidComposition using a link or a pointer? - c ++How to execute dynamically created sql statement - sql-serverhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1794074/assigning-two-coredata-relationships-with-inverse-relationships-to-the-same-entity&usg=ALkJrhioUvMnERSfLZm4KA49bDaKQwu9_gЧто касается профиля и сеанса в asp.net - asp.netHow to create a git workflow on a hero? - gitSimple but complex HQL / SQL query - javaКак создать уникальные идентификаторы для моих масштабированных серверов с PHP? - phpAll Articles