Currently when I have not checked any radio, the button will be disabled. When I check one of the parent radio (eg Parent 1), the button is still disabled, but when I check one of the children of the parent radio, the disabled attribute will be removed.
But when I try to check Parent 2, the button is still active and not disabled.
What I want is when the parent radio is checked, the button will be disabled. However, when selecting the child radio in the checked parent radio, the disable attribute will be removed
$('.checkbox-child').on('click', function(){
$('.submit-button').removeAttr('disabled')
});
.submit-button{
background-color:red;
border:none;
padding:10px 20px;
color:white;
}
.submit-button:disabled{
background-color: grey !important;
}
.checkbox-child-wrapper{
margin-left:20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="checkbox-container">
<div class="item-container" id="parent-1">
<input type="radio" name="check-parent" class="checkbox-parent"> Parent 1
<div class="checkbox-child-wrapper">
<input type="radio" name="check-child" class="checkbox-child"> Child 1
<input type="radio" name="check-child" class="checkbox-child"> Child 2
<input type="radio" name="check-child" class="checkbox-child"> Child 3
</div>
</div>
<div class="item-container" id="parent-2">
<input type="radio" name="check-parent" class="checkbox-parent"> Parent 2
<div class="checkbox-child-wrapper">
<input type="radio" name="check-child" class="checkbox-child"> Child 1
<input type="radio" name="check-child" class="checkbox-child"> Child 2
<input type="radio" name="check-child" class="checkbox-child"> Child 3
</div>
</div>
</div>
<button class="submit-button" disabled>Submit</button>