JSFiddle - React, Tailwind, and code Playground
HTML
<ul>
<li>not empty</li>
<li><!-- comment (should be considered empty --><!-- test --></li>
<li> </li>
<li></li>
<li><span> </span></li>
</ul>
CSS
li {
display: block;
height: 20px;
background-color: red;
margin-bottom: 2px;
}
li.empty {
background-color: green;
}
JavaScript
(function($){
$.isBlank = function(html, obj){
return $.trim(html) === "" || obj.length == 0;
};
$('li').each(function() {
if($.isBlank(
$(this).html(),
$(this).contents().filter(function() {
return (this.nodeType !== Node.COMMENT_NODE);
})
)) {
$(this).addClass('empty');
}
});
})(jQuery);