jquery - Select only one checkbox in bootstrap -
i have few check boxes in different table rows same class name. want 1 should selected among them @ time. trying following nothing working,
$('.sev_check').click(function() { $('.sev_check').not(this).prop('checked', false); });
or,
$('.sev_check').click(function() { $cur=$(this).prop('checked'); $(".sev_check").each(function(){ $(this).prop('checked',false); }) $(this).prop('checked', $cur); });
here how checkboxes aligned,
html,
<div class="checkbox text-center"> <label class="form-checkbox form-icon"> <input id="s_fac" type="checkbox" class="sev_check"> </label> </div>
your first approach works me can see in snippet, can use different approach like:
$(function () { $('.sev_check').change(function(e) { e.preventdefault(); $('.sev_check').not(this).prop('checked', false); $(this).prop('checked', true); }); });
$(function () { $('.sev_check').click(function(e) { $('.sev_check').not(this).prop('checked', false); }); });
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <div class="container"> <form role="form"> <div class="checkbox text-center"> <label class="form-checkbox form-icon" for="s_fac"> <input id="s_fac" type="checkbox" class="sev_check"> </label> </div> <div class="checkbox text-center"> <label class="form-checkbox form-icon" for="s_fac1"> <input id="s_fac1" type="checkbox" class="sev_check"> </label> </div> <div class="checkbox text-center"> <label class="form-checkbox form-icon" for="s_fac2"> <input id="s_fac2" type="checkbox" class="sev_check"> </label> </div> </form> </div>
Comments
Post a Comment