This shoud do the job... $("tr." + i).each(function() { var ithis = $(this).find("td:lt(3)").map(function() { if ($(this).html() === "0") { return null; } else { return this; } }).min(); $(this).find("td.r1").empty().append(roundVal(ithis)); });
so, you select the first 3 cells, and then do the map function, which is similar to each... for every selected cell, if its content is "0", then "deselect" it... so after the map function, you only have those cells that doesn't contain "0", on them you run min()....