You can do this using the following jQuery.
window.onload = function(){ // When the page has finished loading.
$(".nested").each(function(){ // Check every "nested" class
if($(this).children().length == 0){ // If this nested class has no children
$(this).hide(); // This will hide it, but not alter the layout
// $(this).css("display", "none"); // This will alter the layout
} else{
$(this).show();
//$(this).css("display", "none"); // This will alter the layout
}
}
}
Or, as user Rory McCrossan suggested, much more simply written :
window.onload = function(){
$('.nested:not(:has(li))').hide(); // Will not alter layout
// $('.nested:not(:has(li))').css("display", "none"); // Will alter layout
}
` in question contains white-space, which the `:empty` selector won't match for.
– George Nov 14 '18 at 15:40