How to insert external stylesheet in JavaScript (dynamically)
<p>...with right path.</p>

<p>For example. I have script called foo.js. I'd like to insert stylesheet declaration which I can do with following instruction:</p>

<pre><code>$('head').append('&lt;link rel="stylesheet" href="/template/foo.css" type="text/css" /&gt;');
</code></pre>

<p><strong>Problem</strong>: I have to put full path to the stylesheet file. So instead of /template/foo.css I have to put: <a href="http://hostname/directory/template/foo.css" rel="nofollow">http://hostname/directory/template/foo.css</a>. I can't set it statically beacause script can be placed in different servers and different locations. So it can be: <a href="http://foo.com/bar/foo.css" rel="nofollow">http://foo.com/bar/foo.css</a> or <a href="http://foo.com/foo.css" rel="nofollow">http://foo.com/foo.css</a>. </p>

<p>It would be very useful if I can get path of foo.js file on the server. That would be good enough beacause then I could set stylesheet location based on the javascrpt's file.</p>
