I would suggest so
$(".wrapper *").each(function(){ if ($(this).text().trim().length) { $(this).addClass("right"); }});
but the approach has cons. And the first minus is that it will add a class even where there is no text, but there is a child element with text. http://jsfiddle.net/ovzfvrgk/1/ PS I noticed the comments - he essentially answers the same question
Edit:
$(".wrapper *").each(function(){ var element = $(this); var isParent= element.get(0).childElementCount>0; if (element.text().trim().length && !isParent) { element.addClass("right"); } });
If I understand you correctly, then this option should help - it will not mark the parent unit.
http://jsfiddle.net/ovzfvrgk/5/