In CSS, any image path is relative to the CSS file location.
f.ex if I put the CSS file in /media/css/mystyles.css and use something like
/media/css/mystyles.css
Inspired by bobince answer above, I wrote a jQuery version. Here is the code in one line:
var scriptpath = $("script[src]").last().attr("src").split('?')[0].split('/').slice(0, -1).join('/')+'/';
Edit: Filter the script tag by the src attribute, so that we get a src to work on.
script
src