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

:胎

更多相关文章

  1. jQuery遍历----------(遍历、祖先、后代、同胞、过滤)
  2. jQuery -> 获取后代元素的三种方法

随机推荐

  1. Android Studio生成APK自动追加版本号
  2. Android support 26升级到28特性总结
  3. 基于Android不同版本对应notification机
  4. Android 通话记录分析
  5. Android封装Toast工具类
  6. android拖动图片移动效果
  7. [置顶] Android中显示AlertDialog对话框
  8. android ftp服务器实现
  9. 监听Bluetooth
  10. android ClassNotFoundException: Didn't