繁体   English   中英

获取jquery中第n个div的子元素

[英]Getting child elements of the nth div in jquery

假设我有以下 HTML:

<div>
  Project Name
</div>
<div>
  Project Description
</div>
<div>
  <div>
    Metadata 1 <!-- I want this -->
  </div>
  <div>
     Metadata 2 <!-- And this -->
  </div>
</div>

如何使用$(elem).find()获取Metadata 1Metadata 2

我正在尝试这个,但没有运气:

$(elem).find(div[3]:nth-of-type(1))'  // getting first element of the third div
$(elem).find(div[3]:nth-of-type(2))'  // getting second element of the third div

这将 select 第 3 个 div 的直接 div 子级。 您当然也可以使用 jQuery : $('that-selector').text()

 .a-container div:nth-child(3)>div { padding-left: 40px; } /* or safer: .a-container>div:nth-child(3)>div { padding-left: 40px; } */
 <section class="a-container"> <div> Project Name </div> <div> Project Description </div> <div> <div> Metadata 1 <!-- I want this --> </div> <div> Metadata 2 <!-- And this --> </div> </div> </section>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM