Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:20:47+00:00 2026-05-27T07:20:47+00:00

Below I have a nested if statement which loads a certain CSS file depending

  • 0

Below I have a nested if statement which loads a certain CSS file depending on a users device. I also have a style sheet switcher which needs the CSS files to be loaded if a certain device is being used.

if(navigator.userAgent.match(/Windows NT/i)){
if(window.innerWidth < 816){document.write('<link rel="stylesheet" type="text/css" href="ui/tablet/css/site.css">');}
else{document.write('<link rel="stylesheet" type="text/css" href="ui/root/css/site.css title="default"><link rel="alternate stylesheet" type="text/css" href=""ui/root/css/reverse.css" title="reverse"/>');}}

The problem lies with the last line. I am trying to ‘load’ not write multiple CSS files when a page is loaded. I need there to be multiple CSS files loaded as I have a style sheet switcher and it depends on the CSS files which are basically pre-loaded.

I obviously cannot use document.write with multiple CSS files like the above code. I also shouldn’t be using document.write anyway because if a user does change the style sheet, on a refresh it will write an older CSS file anyway.

I have tried being as clear as possible but I’m basically working with many different devices here and also allowing users the opportunity to change style sheets. Risky, I know!

Is there anyway I can change the document.write to something like document.load? Or is there no possible way of loading multiple style sheets depending on a users device?

Thanks, John.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:20:47+00:00Added an answer on May 27, 2026 at 7:20 am

    Something like this will help:

    var cssFilesArr = ["first.css", "second.css"];
    function loadcssfile(cssFilesArr){
    for(var x = 0; x < cssFilesArr.length; x++) {
      var fileref=document.createElement("link");
      fileref.setAttribute("rel", "stylesheet");
      fileref.setAttribute("type", "text/css");
      fileref.setAttribute("href", cssFilesArr[x]);
      document.getElementsByTagName("head")[0].appendChild(fileref);
     }
    }
    loadcssfile(cssFilesArr) ////dynamically load and add this css file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nested div (see below) which have different CSS classes to give
I have below is the html code for TD which gets appended after matching
i'm working on a app where i have nested tree structure i.e. as below
In the code below I have 2 divs, each having two nested divs. When
I have a nested unordered list which has main content on the left, and
Let's suppose I have below nested/multi-dim array: array( 'World'=>array( 'Asia'=>array( 'Japan'=>array( 'City'=>'Tokyo' ) )
I have a tricky CSS situation here. Basically I have nested span tags that
I'm making a sub nav in wordpress and have a nested list style menu.
I have a nested list like below (but it has 1,000's of the holder
I have a nested loop structure in my code. Sometimes, I get the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.