rooz rooz - 6 months ago 58x
Javascript Question

jQuery get background image URL without the quotes?

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:


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(')','');


could someone please advise on this issue?


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

    .replace(/"/g, "")