确定元素是否是其父元素的最后一个子元素 [英] Determining if the element is the last child of its parent
本文介绍了确定元素是否是其父元素的最后一个子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery,有没有一种快速的方法来知道某个元素是否是其父元素的最后一个孩子?
Using jQuery, is there a quick way of knowing if an element is its parent's last child?
示例:
<ul>
<li id="a"></li>
<li id="b"></li>
<li id="c"></li>
</ul>
$('#b').isLastChild(); //should return FALSE
$('#c').isLastChild(); //should return TRUE
推荐答案
使用>:last-child 选择器和.is()
Use :last-child selector together with .is()
$('#c').is(':last-child')
这篇关于确定元素是否是其父元素的最后一个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文