NOTE. Finally, I found an exact duplicate question and a good answer at Get script path
I have a background image defined using a path relative to my css file.
.my-image-class {
background-image: url("../images/my_bg_image.png");
}
I would like to change this path in JavaScript so that it points to now ../images/my_updated_bg_image.png. However, simply changing the style declaration in JavaScript unfortunately changes the value 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 there is no way to extract the absolute source URL of the current JavaScript function being executed? This will give me the same information, because my JS files are also related to image files.
Other solutions?
This is a similar question for javascript - How to use image file relative to URL path? but the class redefinition proposed for me will not work because in fact I have a list of variables of these background images.
EDIT: reference information. The web application (based on Django) serves for HTML content completely separate from the static js, image and css files. Static content is in
static/
js/
css/
images/
file structure. Therefore, I know the relative relationship between these files. However, the absolute URL of HTML content and static content is likely to change. Therefore, I do not want to mix HTML content into my js files in a hard-coded URL if I can avoid it. I get a third-party Django template, so I would also like to avoid editing it.