Toggle between two stylesheets

后端 未结 7 1678
北荒
北荒 2020-12-11 03:38

I am trying to add in a very simple method of switching between 2 stylesheets.

I can get the stylesheet to fire on click but not able to toggle it back to its origin

7条回答
  •  余生分开走
    2020-12-11 03:58

    A better, and more reliable, solution would be to use a single stylesheet and alternate the styling by making the rules depend on a class on the body. You can then just toggle that class when needed, something like this:

    $('#css_toggle').click(function() {
      $('body').toggleClass('default highlight');
    });
    body.default .sq {
      border: 1px solid #C00;
    }   
    
    body.highlight .sq {
      background-color: #CC0;
      border: 2px dotted #C00;
    }
    
    .sq {
      margin: 10px 0 0;
    }
    
    
      
      
    Foo

提交回复
热议问题