I’m trying to add a class to a few cells in a table if their numeric value is greater or equal to a certain value.
This is the code I have. re is the threshold for adding the class.
$("#battersTable td.runs").each(function() {
if($(this).html() >= re) {
$(this).addClass("elite");
}
});
However, the condition of the if statement always appears to be evaluating to true and the class is always being added! What am I doing wrong?
The statement:
is likely not doing what you want it to do.
If these are supposed to be numbers for a numeric comparison, then you need to parse the string into a number (and re must be a number too) before doing a numeric comparison:
An example of what both
reis and what$(this).html()is would allow us to give more specific answers.