How to use cookies to change css ?

Tags: javascript,html,css,cookies,href

Problem :

i'm using this script to change the css link href="#" on the targeted document:

<script type='text/javascript'>
function toggle() {
    var el = document.getElementById("style1");
    if (el.href.match("css/style.css")) {
        el.href = "css/style-b.css";    
    else {
        el.href = "css/style.css";  


<link id="style1" rel="stylesheet" href="css/style.css" type="text/css" media="screen">

and with button click:

<button type="button" onclick="toggle()">Switch</button>

but with this click i need to change the css link href="#" to all my .html documents.

how to do this with cookies?

(btw i'm beginner with cookies and js.. so i will need the whole code if can)


Solution :

The following article explains exactly what you are looking for - the ability to define alternative style sheets, how to switch between them, and to store that choice in a cookie.

Read the article first, but see also the completed example JavaScript file Paul Sowden has written:

    CSS Howto..

    How can have all the images show up on my slider whilst differentiating each image with its own div tag?

    CSS3: How do I make a linear gradient on top of an image suitable for cross browser compatibility?

    Bootstrap: how to clear images in a gallery?

    How to fix width of DIV that contains floated elements?

    How to cut the bottom overflow of page CSS/HTML

    How can I force text to “normal” (not bold) using css?

    how to achieve the moving sparking effect with css and javascript as in footer

    How to center a text nav bar with CSS

    How to debug HTML/CSS for iPhone/iPad performance?

    How to Fix Collapsing Top and Bottom Margins?

    How can I style a JavaFX menu and its items in CSS?

    how to load different css files with different screen sizes?

    how to modify height of a div when hover it and with transition (priority of CSS without Javascript)

    Keep mobile browser from showing elements outside body?

    How to make a web form with 3 columns?

    How do I wrap a overflowed span in fixed div

    how to make a CSS animation end point the right edge of the browser

    How to stop a CSS rule from applying to a specific element [duplicate]

    css how to make this checkbox smaller

    How to perfectly center contents in an unordered list?

    How to display child elements of
  • at 100% height?
  • How can I use CSS to make a div float over my text whilst remaining in the right spot?

    How to set min-height of div to height of viewport?

    How to create a line break instead of having text going on top of itself?

    How is CSS linked to [closed]

    How do I make this carousel implementation better?

    How to adjust website according to screen resolution

    How do I center a background image to its parent element?

    How to place content below a fixed image?

    How can I avoid CSS delay in Rails 3.2