在 jQuery 中,如何访问克隆的 div 对象中的子 div?
我首先运行它来获取我的克隆数据
var cloned = $(".hoverer:first").clone().attr({id: 'id_'+itm_id, class: 'hoverer-active'});
该div中有一个div,其中有id和class,该div也有一个div,其中有id和class,我正在尝试访问第三个div的数据?
<div id="id_2" class="hoverer-active">
<div id="sub1" class="test">
<div id="bus2" class="tset">
data i want to play with
</div>
</div>
</div>
I first run this to get my cloned data
var cloned = $(".hoverer:first").clone().attr({id: 'id_'+itm_id, class: 'hoverer-active'});
That div has a div within it that has an id and class, and that div also has a div in it that has id and class, and I am trying to access the data of the 3rd div?
<div id="id_2" class="hoverer-active">
<div id="sub1" class="test">
<div id="bus2" class="tset">
data i want to play with
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
cloned
变量作为新 jquery 命令的上下文 ..所以你也可以这样做
,因为
cloned
变量保存一个 jquery 对象,你可以使用.find
方法来查找其中的内容..You can use the
cloned
variable as the context of new jquery commands..So you can do
alternatively, since the
cloned
variable holds a jquery object you can use the.find
method to find content inside it..这是克隆对象中该 div 的选择器。请记住,在 jquery 中,当选择元素时,您可以提供第二个参数来定义要搜索的上下文。
This is the selector for that div within your cloned object. Rembember in jquery when selecting an element you can provide a second parameter that defines the context in which to search.
这是一个带有示例的 jsFiddle : http://jsfiddle.net/DavidLaberge/bjNMj/
Here is a jsFiddle with an example : http://jsfiddle.net/DavidLaberge/bjNMj/