I would like to know how do I block a checkbox
as a bootstrap
button since I have it and I make a simple limit check in 2 or only 2 checkbox
can be selected. When I select the third checkbox
it shows me my error message and selects my checkbox
. I would like that when it selects the third checkbox
of the error message and does not select
$('input[type=checkbox]').on('change', function () {
var total = $('input[type=checkbox]:checked').length;
$(this).closest('.hovereffect').toggleClass('clic');
if(total > 2){
$('input[type=checkbox]').attr('disabled', true);
alert("Você ultrapassou seu limite");
return;
}
});
.btn-group{
margin-top:20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary check">
<input type="checkbox" autocomplete="off"> Selecionar
</label>
<label class="btn btn-primary check">
<input type="checkbox" autocomplete="off"> Selecionar
</label>
<label class="btn btn-primary check">
<input type="checkbox" autocomplete="off"> Selecionar
</label>
<label class="btn btn-primary check">
<input type="checkbox" autocomplete="off"> Selecionar
</label>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>