Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
41
rated 0 times [  42] [ 1]  / answers: 1 / hits: 11273  / 8 Years ago, sun, april 17, 2016, 12:00:00

I'm trying to use jQuery to get the background image URL of a div but without any quotes.



So basically all I need is the URL/Path to the image.



I'm using the code bellow but this code gives me a URL like this:



http://somesite.com/images/apple.png


As you can see, it will place the URL between double quotes which is not what I want.



Here is the code:



var bg = $('.selected').css('background-image');
bg = bg.replace('url(','').replace(')','');

alert(bg);


could someone please advise on this issue?


More From » jquery

 Answers
4

Replacing with RegEx //g will give me what you want:





alert(
'http://somesite.com/images/apple.png'
.replace(//g, )
);




[#29398] Friday, April 15, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnnyblaynes

Total Points: 667
Total Questions: 121
Total Answers: 102

Location: Anguilla
Member since Sat, Jan 23, 2021
3 Years ago
;