I have this code:
$(document).ready(function() {
var MidUpperArmCircumference = 0;
var TricepsSkinfold = 0;
function checkMethod(method,parameters){
$('#'+method+'_check').change(function() {
if (this.checked == true) {
$.each(parameters, function() {
$('.'+this).css('color','blue');
this++; //HERE IS THE ERROR!
});
}
});
}
var parametersMuscleArea = ['TricepsSkinfold', 'MidUpperArmCircumference'];
checkMethod('MidUpperArmMuscleArea',parametersMuscleArea);
});
How can I increase the variables TricepsSkinfold and MidUpperArmCircumference inside the $.each function?
thisis the string, not the a reference to the local variable. You can’t increase your variable by increasing the string. Also, you’re trying to refer to a local variable by a name as given in a string. With local variables, this can only be done viaeval, or by namespacing the variables.This will work: