jQuery.find()忽略根节点 [英] jQuery.find() ignores root node
本文介绍了jQuery.find()忽略根节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的jQuery对象看起来像这样:
My jQuery object looks like this:
var myJq = jQuery("<div class='a'></div><div class='b'></div>")
myJq.find(".a")
返回一个空的jQuery对象,显然是因为find()
仅搜索jQuery对象中包含的节点的 children ,而不搜索节点本身.
myJq.find(".a")
returns an empty jQuery object, apparently because find()
searches only the children of the nodes contained in a jQuery object, not the nodes themselves.
如何使用选择器在myJq
中抓取一个div?
How can I grab one of the divs in myJq
using a selector?
推荐答案
您需要改用 .filter()
.
You need to use .filter()
instead.
这将过滤jQuery对象顶层的项目.
This will filter through items at the top level of the jQuery object.
myJq.filter(".a")
这篇关于jQuery.find()忽略根节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文