Switching between css stylesheets

前端 未结 1 869
无人及你
无人及你 2021-01-24 17:08

So, unlike other questions about this, I want to use this code from here: How do I switch my CSS stylesheet using jQuery?

I need to switch between multiple css styles in

相关标签:
1条回答
  • 2021-01-24 17:21

    Yes, it will work. Whether <link> is either in the <head> or <body>.

    Here's a basic sample,

    var isToggled = false;
    $(function() {
      $('#btnSwitchCss').on('click', function() {
        isToggled = !isToggled;
    
        if (isToggled) {
          $("link[href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css']").attr('href', '../');
        } else {
          $("link[href='../']").attr('href', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
        }
      })
    
    });
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    
    <div class="container">
      <h2 class="text-center"> Switch CSS Style </h2>
      <button id="btnSwitchCss">Switch</button>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    0 讨论(0)
提交回复
热议问题