snipt

Ctrl+h for KB shortcuts

Text only

Add External CSS File with jQuery

1
2
3
4
5
6
7
8
9
$(document).ready(function(){
   $("head").append("<link>");
   var css = $("head").children(":last");
   css.attr({
     rel:  "stylesheet",
     type: "text/css",
     href: "CSS/Demo.css"
  });
});
https://snipt.net/embed/3f7bf095e7b919a702cd59e7de6115d3/
/raw/3f7bf095e7b919a702cd59e7de6115d3/
3f7bf095e7b919a702cd59e7de6115d3
text
Text only
9
2019-07-15T18:08:18
True
False
False
Jul 11, 2012 at 09:38 AM
/api/public/snipt/43766/
add-external-css-file-with-jquery
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a> <a href="#L-9">9</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$(document).ready(function(){ </span><span id="L-2"><a name="L-2"></a> $(&quot;head&quot;).append(&quot;&lt;link&gt;&quot;); </span><span id="L-3"><a name="L-3"></a> var css = $(&quot;head&quot;).children(&quot;:last&quot;); </span><span id="L-4"><a name="L-4"></a> css.attr({ </span><span id="L-5"><a name="L-5"></a> rel: &quot;stylesheet&quot;, </span><span id="L-6"><a name="L-6"></a> type: &quot;text/css&quot;, </span><span id="L-7"><a name="L-7"></a> href: &quot;CSS/Demo.css&quot; </span><span id="L-8"><a name="L-8"></a> }); </span><span id="L-9"><a name="L-9"></a>}); </span></pre></div> </td></tr></table>
CSS, jQuery