title: Get relative CSS URL path in Javascript
body: <p>NOTE: I finally found an exact duplicate question and good answer at: <a href="https://stackoverflow.com/questions/2161159/get-script-path">Get script path</a></p>
  
  <p>I have a background-image defined with a path relative to my css file.</p>
  
  <pre><code>.my-image-class {
    background-image: url("../images/my_bg_image.png");
  }
  </code></pre>
  
  <p>I would like change this path in JavaScript so that it now points to <code>../images/my_updated_bg_image.png</code>.  However simply changing the style declaration in JavaScript unfortunately changes the meaning of the relative path from the CSS location to the HTML location.</p>
  
  <p>Is there a way to extract an absolute URL from a relative CSS URL?</p>
  
  <p>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.</p>
  
  <p>Other solutions?</p>
  
  <p>This is a similar question to <a href="https://stackoverflow.com/questions/3612226/javascript-how-to-use-a-image-file-relative-to-a-url-path">javascript - How to use a image file relative to a url path?</a> but the class swapping trick suggested there won't work for me because I actually have a variable list of these background images.</p>
  
  <p>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</p>
  
  <pre><code>static/
    js/
    css/
    images/
  </code></pre>
  
  <p>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.</p>