获取第二个子元素 [英] Getting the 2nd child element

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

问题描述

$

 < div> 
abcsdf
< div>第一个孩子< / div>
< div>第二个孩子< / div>
< / div>

我想得到第二个孩子,他们使用append动态填充,我不知道如何



我想显示



$('第二个元素内部html这里')。对话框()等..



希望有人可以帮助我。



谢谢

解决方案

多种方法可以做到这一点。我将假设顶层div具有顶的ID。这可能是最好的:

  $('#top>:nth-​​child(2)')。whatever( ); 

  $( '#' 顶部)儿童( ':第一子')的next()什么();。 

或者如果您知道事实上至少有2个孩子

  $($('#top')。children()[1])。whatever(); 


I am still new in jquery and I have this code

<div>
   abcsdf
   <div> first child</div>
   <div> second child</div>
</div>

I wanted to get the second child, they are dynamically populated using append and I don't know how to get it.

I wanted to display

$('the second element inner html here').dialog() etc..

Hoping someone can help me.

Thanks

解决方案

A number of ways to do this one. I'm going to assume the toplevel div has an id of 'top'. This is probably the best one:

$('#top > :nth-child(2)').whatever();

or

$('#top').children(':first-child').next().whatever();

or if you know for a fact there are at least 2 children

$($('#top').children()[1]).whatever();

这篇关于获取第二个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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