0

Im trying to load css file in my Jquery function but not able to render the same in UI when i check in View source of page.

   $(document).ready(function () {
        debugger;
        if (Ie.IsBrowserSupported) {
            $("link[href*='site.css']").remove();
            $("head").append($("<link rel='stylesheet' href='ChromeSite.css' 
                type='text/css' media='screen' />"));
        }
    });

ChromeSite.css is not being rendered in stylesheet of the page. Is there Any other way to load the same in Jquery function?

Rupak
  • 61
  • 10
  • 1
    Possible duplicate of [adding css file with jquery](https://stackoverflow.com/questions/5680657/adding-css-file-with-jquery) – cloned Aug 07 '19 at 07:09
  • Did you inspect the result in the dev tools? Did you manually break that long line to post it here or is it like that in your actual code? Are you getting any error messages in the console? When I fix the linebreak issue, the `append()` part works as expected. Keep in mind that "View source" shows the original document received from the server, not the changed DOM! –  Aug 07 '19 at 07:10
  • @cloned that didnt work...that's why posted it. – Rupak Aug 07 '19 at 07:13
  • @ChrisG append is working as expected but my stylesheet are not getting applied to that page – Rupak Aug 07 '19 at 07:14
  • See the network in dev tools for any errors. – Akash Tomar Aug 07 '19 at 07:15
  • In that case there's an issue with your CSS, or the stylesheet `href` is wrong. Adding a stylesheet to a document will apply the styles immediately. –  Aug 07 '19 at 07:15
  • depending on the browser, adding `link` tag to the head tag, won't work. IE is always abit _sensitive_. – winner_joiner Aug 07 '19 at 07:18
  • Please read the linked duplicate post, yours is different. You are appending a jquery object and **not** a stylesheet. – cloned Aug 07 '19 at 07:22
  • @cloned [`append()`](https://api.jquery.com/append/) works with jQuery elements just fine. Again, OP's code is fine. –  Aug 07 '19 at 07:24
  • Here's a plunkr I made in IE11: https://plnkr.co/edit/u6xo0vrg6YJnj3yJP4nK?p=preview It works just fine. –  Aug 07 '19 at 07:25

0 Answers0