NOTE: I finally found an exact duplicate question and good answer at: Get script path
I have a background-image defined with a path relative to my css file.
.my-image-class {
background-image: url("../images/my_bg_image.png");
}
I would like change this path in JavaScript so that it now points to ../images/my_updated_bg_image.png
. However simply changing the style declaration in JavaScript unfortunately changes the meaning of the relative path from the CSS location to the HTML location.
Is there a way to extract an absolute URL from a relative CSS URL?
If not is there a way to extract an absolute URL of the source of a currently running JavaScript function? This would give me the same information because my JS files are also relative to the images files.
Other solutions?
This is a similar question to javascript - How to use a image file relative to a url path? but the class swapping trick suggested there won't work for me because I actually have a variable list of these background images.
EDIT: Background info. The web app (Django based) is serving HTML content entirely separately from static js, image, and css files. The static content is in a
static/
js/
css/
images/
file structure. So I know the relative relationships among these files. However the absolute URL's to the HTML content and the static content will likely be changing. So I don't want mix in hard coded URL's for HTML content into my js files if I can possibly avoid it. I'm getting the Django template from a 3rd party, so I'd also like to avoid editing that as well.