本文介绍了用jQuery获取叶节点的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从DOM中获取所有叶子节点(比如div)?如果没有简单而神奇的选择器,我会尝试寻找一种最佳解决方案.我考虑过使用"reachedElem.find('div').length == 0",但是我不确定这是否是正确的方向.有什么想法吗?
How can one get all the leaf nodes, let's say divs, from the DOM? I am trying to think of an optimal solution, if there's no easy and magical selector for this. I thought of using the "reachedElem.find('div').length == 0" but I am not sure if this is the right direction. Any ideas?
推荐答案您可以使用以下选择器
$('div:not(:has(*))')上面的选择器将选择所有没有子级的DIV.
Above selector will select all the DIVs who don't have any children.
更多推荐
用jQuery获取叶节点的最有效方法是什么?
发布评论