This check isn't working correctly since children() only works one level down and the tr tags are inside a tbody tag. You can change this to parent.find("tr") or change parent to parent = item.parents("tbody")