mercredi 21 octobre 2015

check if nested checkboxes are triggered using jquery

I have 2 divs with check boxes nested in each. I basically would like to trigger an alert if a checkbox is clicked in the 1st one and second one, but I cannot seem to reach that scope. The checkboxes are classes.

if ($("#result1 .tb2:checked").length == 1 && ($("#result2 .tb4:checked").length == 1  ) {
    alert("both clicked");
}
  
<script src="http://ift.tt/1g1yFpr"></script>
<div id="result1">
<input type="checkbox" class="tb1" />&nbsp;&nbsp;Yes<br><input type="checkbox"class="tb2" />&nbsp;&nbsp;No<br><br></div><br>
    
</div>
    
    
    
 <div id="result2">
<input type="checkbox" class="tb3" />&nbsp;&nbsp;Yes<br><input type="checkbox"class="tb4" />&nbsp;&nbsp;No<br><br></div><br>
    
</div>



Aucun commentaire:

Enregistrer un commentaire