I’ve searched various posts and forums but can’t find the right answer. I need to find a way to dynamically load and unload stylesheets.
I’m building a website that has a main stylesheet and 2 optional stylesheets, for example purposes i’m going to use colours. I need to add 2 links, that loads a new stylesheet on click. This stylesheet will override some of the styles from the main stylesheet.
For example:
I have a yellow website, this is what most people want, however i’ve got the option for the user to click red or blue, when they do, the styles in the red stylesheet override the main styles and change the website to red, if they click blue this changes to blue.
To complicate things further, if the user clicks red and loads the red stylesheet and they changed their mind and now want blue, I need the red stylesheet to unload and just load the blue.
I’m not very proficient with javascript so am having issues with this.
Thanks in advance!
I managed to get this working with a little tweaking of:
http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
Content of the link:
Just FYI: For js scripts, this will remove a
scriptelement from the DOM but most browser will not unload the js code i.e. anything defined in the js file will stay defined.