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

前端 未结 5 2628
眼角桃花
眼角桃花 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:38

    This is what you are looking for:

    $(function(){
        $('tr').each(function(){
            var _hide = true;
            $(this).find('td:not(.requirementRight)').each(function(){
                if($(this).text().trim() != ''){
                    _hide = false;
                }
            });
    
            if(_hide){
                $(this).hide();
            }
        });
    })
    

    You check every row for content other than whitespace and hide the row if none was found. have fun! working example: http://jsfiddle.net/kvCXa/7/

提交回复
热议问题