Hide row if it contains empty columns

前端 未结 4 1448
我在风中等你
我在风中等你 2021-01-21 08:26

I have a table with a couple of rows, each row with two columns, the first column will hold title and second column will have the respective values.sometimes, cells in the right

相关标签:
4条回答
  • 2021-01-21 08:58

    Try this:

    $('.EventDetail tr').each(function(){      
        if ($('td:empty',this).length > 0))
        $(this).hide();
    });
    
    0 讨论(0)
  • 2021-01-21 09:01

    I think this will work:

    $('.EventDetail tr').has('td:nth-child(2):empty').hide()
    

    You can try it on jsFiddle.

    0 讨论(0)
  • 2021-01-21 09:07

    You can try this:

        $(document).ready(function(){
        $('.EventDetail tr').each(function(){      
            if ( $(this).children().not('.TableFields').text().length == 0 )
                $(this).hide();
        }); 
    });
    
    0 讨论(0)
  • 2021-01-21 09:14

    Your selector will cause the if statement never to be true for any row in your example. $("td:not(:empty)") always selects the <td> element with the title, so length is always 1. if(!1) is never true.

    You should remove the double negative (the ! and the :not) to make it clearer, and then check that the length (i.e. number of matched elements) is > 0.

    0 讨论(0)
提交回复
热议问题