如何使用JQuery获取div中的第一个子代码 [英] How to get the first child id inside the div using JQuery
本文介绍了如何使用JQuery获取div中的第一个子代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用JQuery获取div中的第一个子代码。
How to get the first child id inside the div using JQuery.
示例代码:
<div id='id1'>
<a id='a1' />
<a id='a2' />
<a id='a3' />
</div>
我想获取id a1
。
我尝试过 $('#id1 a:first-child')。html()
文本。如何获取ID?
I have tried $('#id1 a:first-child').html()
to get the text. How to get the id?
推荐答案
$("#id1:first-child").attr("id")
这篇关于如何使用JQuery获取div中的第一个子代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文