使用jQuery获取UL的第一个LI的ID [英] Get ID of first LI of UL with jQuery

查看:1228
本文介绍了使用jQuery获取UL的第一个LI的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<ul id="someList">
<li id="listItem1">List 1</li>
<li id="listItem2">List 2</li>
</ul>

也许我需要刷新我的选择器,但是如何获取ul的第一个ID# someList?

Maybe I need to brush up on my selectors, but how would you grab the first ID of ul#someList?

此外,如果我将LI加到ul#someList,我需要以不同的方式获取第一个LI的ID吗?

Also if I'm prepending LI's to ul#someList, will I need to grab the first LI's ID in a different way?

推荐答案

$('ul#someList li:first')

这篇关于使用jQuery获取UL的第一个LI的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆