Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to append Style Sheets in IE using jQuery?
    text
    copied!<p><strong>Hello Guys,</strong></p> <p>I was just trying to create a plugin, and I needed it to be user-friendly so I want to <code>append</code> the <code>&lt;link/&gt;</code> tag on the <code>head</code> portion of the users page as my plugin is loaded. It works fine with all the other browsers (not sure of IE9, IE7 &amp; IE6) but doesn't work for IE8! I don't what is getting wrong with my plugin, so I just created a sample page and faced the similar problem! Here is my test page HTML+jQuery Code ------</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="../jquery-1.6.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { $(document.head).append('&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;'); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Text!&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here is my CSS code -----</p> <pre><code>body { background:#ddd; } h1 { color: #789; } </code></pre> <p>So can anyone tell me where I'm going wrong or is this the problem of lifetime?</p> <p><strong>THANKS IN ADVANCE</strong></p> <hr> <p>After seeing the first comment and going to link supplied, I just created this sample code and found something amazing! See this ~~~</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="../jquery-1.6.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { if (document.getElementsByTagName('head')[0] === document.head) { $("head").append('&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;'); }else { alert('This doesn\'t supports head appending!'); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Text!&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>On executing this page with my IE8 browser I get the message that </p> <pre><code>This doesn't supports head appending! </code></pre> <p>Well I don't what is wrong with my browser or is this the fault of IE8? </p> <hr>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload