tags:

views:

24

answers:

1

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() == '');
        })
+4  A: 

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().

Nick Craver