开发者

How to find if table cells don't contain xx

I'm looking create a piece of jQuery logic that answers:

Are there any tables cells that don't contain '' or 'xx' and don't have the class 'yy'

This is my effort - but it seems really messy?:

$('td').filter(function(index) {
            return  !$(this).hasClass('yy') &&
                    !($(this).html().trim() == '' || $(this).html().trim() == ''开发者_高级运维);
        })


You can use :not(), for example:

$('td:not(.yy):not(:contains(xx)):not(:empty)')

This checks for cells that do :not() have the .yy class, do :not() contain "xx" and are :not() :empty.

If you need to trim, I'm leave the .filter(), for example:

$('td:not(.yy)').filter(function() {
  var thtml = $.trim(this.innerHTML);
  return thtml != '' && thtml != 'xx';
});

Note I'm using $.trim() since not all browsers support String.trim().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜