如何在jQuery中选择最后一个子元素?
16lz
2021-01-22
How to select last child element in jQuery?
如何在jQuery中选择最后一个子元素?
Just the last child, not its descendants.
只是最后一个孩子,不是它的后代。
4 个解决方案
#1
93
You can also do this:
你也可以这样做:
<ul id="example">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ul>
// possible 1
$('#example li:last').val();
// possible 2
$('#example').children().last()
// possible 3
$('#example li:last-child').val();
:last
:去年
.children().last()
.last定格()()
:last-child
:胎