hide cell content if child spans are empty

ぐ巨炮叔叔 提交于 2019-12-02 11:55:30

As you don't include your final html it is tough to say. Always try and include what we will see on the page, not generic sharepoint calls.

http://jsfiddle.net/Ctjcv/7/

In this example I check whether each cell contains any children other than the map class. If not then we can safely hide it. You will see that cell1 shows the link because other data is present while cell 2 does not.

$('.OfficeInfo td').each( function() {
    if ($(this).children(':empty').not('.mapdirectionsLink, br').length > 0) {
        $(this).children('.mapdirectionsLink').hide();   
    }
});

You can use text() method for that

$('.OfficeInfo tr td').each(function() {
    if ($(this).children().not('.mapdirectionsLink').text().replace(/^\s+|\s+$/g,"") == '') {
        $(this).children('.mapdirectionsLink').hide();
    }
});

You can find JSFiddle here

There is an extra trim control..

EDIT : I just add some extra to mrtsherman's solution..

EDIT 2 : I changed function to hide all elements if there is no map info JSFiddle here
If you want to remove the elements (not hiding) you can change

$(this).children('*').hide(); 

line with:

$(this).children('*').remove();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!