Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make toggle button switch use boostrap 5?

I have a proble to make a toggle switch button, and I do not know how to do it. Here is my code that I try to do, I hope someone can help me:

<div class="btn-group" checked data-toggle="toggle" role="group" aria-label="Basic mixed styles example">
            <button type="button" class="btn btn-danger">Month</button>
            <button type="button" class="btn btn-danger">Year</button>
</div>

Toggle switch like this:
Toggle switch change between month and year

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assumed you would be using jquery (bootstrap), Ypu can further style as you see fit

(function($) {
  'use strict';

  $(document).ready(() => {

    $("input[type='button']").click((event) => {
      $("input[type='button']").toggleClass("btn-toggle");
    });

  });

})(jQuery);
input[type='button'].btn-toggle {
  background: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<div class="m-5" role="group" aria-label="Basic mixed styles example">
  <input type="button" class="btn btn-toggle" value="Month">
  <input type="button" class="btn" value="Year">
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading