所以我有动态内容,想删除空元素和空子元素(如果有的话)。有几种情况发生:
HTML
<p> </p>
<p><img src="image.jpg" /></p>
<p><strong></strong></p>
jQuery
$(".articleContent p").filter( function() {
return !($.trim($(this).text()).length) && !($(this).children().length);
}).hide()
问题是它没有考虑空子元素。我尝试过调整,它要么隐藏 img 要么隐藏空子元素。
建议?