$(null)
is an empty jQuery object, not null
. And all objects are truthy.
If you want to test null, use this === null
. You don’t need jQuery for this.
However, I don’t see why do you expect this
to be null sometimes. Instead, it seems you want to ignore whitespace text nodes.
var $elements = $('.webgrid-footer td').contents().filter(function() {
return (this.nodeType === 3 && $.trim(this.nodeValue) !== '')
|| this.nodeType === 1;
});
6
solved How to capture null in javascript