$('span:empty').addClass('foo');
Just keep in mind that empty-selector (docs) means completely empty, which means spaces.
If you want to allow spaces, do the following:
$('span').filter(function() {
return !$.trim( this.innerHTML );
}).addClass('foo');
It uses the jQuery.trim() (docs) method inside filter() (docs) to allow elements that have only whitespace content (no elements).
source
share