toggle switch
by alfredopacino
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/css-toggle-switch@latest/dist/toggle-switch.css" />
<script>
</script>
<div class="switch-toggle alert alert-light col-lg-9">
<input id="week-d1" name="view-d" type="radio" checked disabled>
<label for="week-d1" onclick="">Week</label>
<input id="month-d2" name="view-d" type="radio" disabled>
<label for="month-d2" onclick="">Month</label>
<input id="month-d3" name="view-d" type="radio" disabled>
<label for="month-d3" onclick="">Year</label>
<a class="btn btn-primary"></a>
</div>
<input id="button" type="button" value="toggle" />
CSS
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.switch-toggle input[disabled] + label{
background: white;
color:grey
}
.switch-toggle input[disabled][checked] + label{
background: grey;
color:white
}
JavaScript
let enabled = true
document.getElementById('button').addEventListener('click', function(event) {
$(".switch-toggle input").attr('disabled',enabled = !enabled);
});