$("input[type='checkbox']").change(function(){
if(this.checked){
if($(':checkbox:checked').length>1 && $('#qT').val()==1){
$(this).prop( "checked", false );
}
}
});
this is the script to run
And html looks like below
<div class=row>....
<div class="isCorrect">
<span>correct</span>
<input type="checkbox" class="form-check-input mx-1"value="1">
</div>...</div>
<div class=row>....
<div class="isCorrect">
<span>correct</span>
<input type="checkbox" class="form-check-input mx-1"value="1">
</div>...</div>
etc etc
This code only checks the first check box. not any other..
I also tried
$("input[type='checkbox']").change(function(){
if(this.checked){
if($(':checkbox:checked').length>1 && $('#qT').val()==1){
$(this).prop( "checked", false );
}
}
}).triger(change);
and many other ways
>Solution :
Your code is not working because your event handler is created before the dynamic checkboxes are. To bypass this, you can bind an event handler to the whole document or, for better performance, to the parent that contains all your checkboxes :
$(document).on('change',"input[type='checkbox']",function () {
// your code here...
});