Say that you have a loop and depending on the outcome of the loop you add a class name to DIV, either Y or N. Based on Y or N you want to change the css properties of that class. See code below:
function percentageCount() {
$(".Parent").children().each(function(i, valOuter) { // Outer Loop
alert("Outer loop");
alert($(valOuter).html());
var totalPercentage = 0;
$(valOuter).children().find(':input').each(function(ii, valInner) { // Inner Loop
// alert("Inner loop");
totalPercentage += parseInt(this.value);
// alert("total percentage: " + totalPercentage);
if (this.value == '') {
totalPercentage += 0; // Assume empty string == 0
}
if (totalPercentage == 100) {
alert("Percentage equals to 100");
$(valOuter).removeClass("N");
$(valOuter).addClass("Y");
}
else {
alert("Percentage must equal to 100");
$(valOuter).removeClass("Y");
$(valOuter).addClass("N");
}
}); // Inner Loop
}); // Outer Loop
// Code to search for JQuery class
});
What would be a good way of doing this?
Thanks
1 Answer