There is such a piece where how
$(document).on('click', '#calcA', function() {
$("#calcASum").addClass("field");
($(this).is(":checked")) ? $("#calcAInfo").css("display", "") : $("#calcAInfo").css("display", "none");
});
$(document).on('click', '#calcB', function() {
$("#calcBSum").addClass("field");
($(this).is(":checked")) ? $("#calcBInfo").css("display", "") : $("#calcBInfo").css("display", "none");
});
$(document).on('click', '#calcC', function() {
$("#calcCSum").addClass("field");
($(this).is(":checked")) ? $("#calcCInfo").css("display", "") : $("#calcCInfo").css("display", "none");
});
only AB and C changes; I wanted to write through for ()
var item = ['A', 'B', 'C'];
for(var i=0; i<item.length; i++) {
$(document).on('click', '#calc'+item[i], function() {
$("#calc"+item[i]+"Sum").addClass("field");
($(this).is(":checked")) ? $("#calc"+item[i]+"Info").css("display", "") : $("#calc"+item[i]+"Info").css("display", "none");
});
}
he adds one more function after the click function. It turns out inside the function already i = 3. There are other solutions to this problem? thanx