Is there a JavaScript version of the following. It works as I want, but it looks a bit messy and I’ve read that sometimes breaking from an outer for loop within a .each loop is more neatly achieved with Javascript.
for(array to iterate over){
var abSelected = false;
$("input[type='checkbox'][id*=AB]:checked").each(function() {
abSelected = true;
}
if(abSelected){
break;
}
...do other stuff...
}
I think the if statement is unnecessary. I want to loop all checkboxes beginning with ‘AB’ and break from the outer for loop if any are selected.
Thanks.
you can simply check on the length of the
selected checkboxes beginning with 'AB'collection returned by jQuery, if > 0, break: