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 6597401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:12:14+00:00 2026-05-25T18:12:14+00:00

I have a page that allows users to dynamically change the loaded theme (stylesheet).

  • 0

I have a page that allows users to dynamically change the loaded theme (stylesheet). I have a themeStyle <link> element that stores the currently loaded stylesheet. I’m switching it like this

function switchTemplate(stylePath){
    var ns = $('<link>', {
            href: stylePath,
            id: 'themeStyle',
            type: 'text/css', 
            rel: 'stylesheet'
        });
    $('#themeStyle').replaceWith(ns);
    self._cssIsLoaded(ns.get(0), stylePath);

}

and then using this function to detect if it’s loaded.

It was working sporadically, but I realized it was probably never working because the #themeStyle css will always be loaded, but not necessarily changed.

I added passing the css file path to the _cssIsLoaded function, but it changes before the load is complete, so I don’t know what to use to check if it has switched.

The only solution I can think of now is to have a hidden div stylePath to it as content: element in every stylesheet, and check if that div’s content is the correct stylePath… but that requires changing every stylesheet, the HTML and the JS as well as just being somewhat cludgy. Is there any more reasonable way to achieve this?

edit: I’ve thought of just adding the new styles at the end, but there’s possibility that not all the styles will be overridden by the new one. There’s a base stylesheet always in place and these particular rules being loaded only affect one part of the page.

  • 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-25T18:12:14+00:00Added an answer on May 25, 2026 at 6:12 pm

    I settled on adding an incrementing number after the id of the style tag, when I switch the style, I add the new stylesheet and remove the old one, then check with the new number to see if it has been loaded.

    function switchTemplate(stylePath){
        var osid = $('[id^="themeStyle-"]');
        var stylenum = osid[0].id.split('-')[1];
        var newstylenum = (Number(stylenum) + 1).toString();
        var ns = $('<link>', {
                href: stylePath,
                id: 'themeStyle-' + newstylenum,
                type: 'text/css', 
                rel: 'stylesheet'
            });
        $("head").append(ns);
        $('#themeStyle-' + stylenum).remove();
        _cssIsLoaded(ns.get(0), stylePath);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that has fields dynamically loaded via JQuery. It allows a
I have a pretty straight forward uploadified page that allows users to upload files,
I have the following: POST page that allows users to write text in CKEditor
I have a page where it allows users to add new ul dynamically using
I have a page that allows the user to download a dynamically-generated file. It
I have a search page that allows the users to filter other users by
I have an ASP.NET (3.5) page that allows a user to upload an Excel
Right now I have a JSP page that allows to sort some items, when
I have a SQL interface page in my classic ASP web app that allows
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when

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.