Toggle between two stylesheets

后端 未结 7 1656
北荒
北荒 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 04:01

    There is the requested simple example:

    HTML:

    <link rel="stylesheet" type="text/css" id='styles' href='path_to_your_style_1'>
    <button id="css_toggle" title="I'm a tooltip!">Text</button>
    

    JS:

     $('#css_toggle').click(function () {
      if ($("link[id='styles']").attr('href') == 'path_to_your_style_1'){
        $("link[id='styles']").attr('href', 'path_to_your_style_2');
      } else { 
        $("link[id='styles']").attr('href', 'path_to_your_style_1');
      }
    });
    
    0 讨论(0)
提交回复
热议问题