jQuery - check for empty TDs and if all empty hide the parent TR

前端 未结 5 2508
眼角桃花
眼角桃花 2021-02-20 01:57

I\'d like to check for empty TDs (classes a-h only) and if all are empty, then I\'d like to hide the parent TR. The issues I\'m running into are, my empty TDs contain \" \"

5条回答
  •  温柔的废话
    2021-02-20 02:49

    firstly, I'd suggest giving the TDs an additional class to distinguish the TDs whose contents are to be checked. below, I used .et (emptyTest).

    the following syntax might be slightly wrong, but it should give you the idea:

    $("tr").each(function() {
      var nonEmpty = $(this).find("td.et").filter(function() {
        return $(this).text().trim() != ""; //check the trimmed TD content - will make it ignore all white space
      });
      if (nonEmpty.length == 0) $(this).hide();
    });
    

提交回复
热议问题