在jQuery中,什么是;查找(';>;span';)”;做

在jQuery中,什么是;查找(';>;span';)”;做,jquery,find,Jquery,Find,我不明白find('>span')做了什么 你能解释一下吗 HTML代码 <button>Ibis<span class="bg"><span>Ibis</span></span></button> $(this).find('> span').animate( { width: '100%' } ); $(this).find('>span') 查找此 在您的示例中,它查找,但不查找该中的 Jquery选择器的工

我不明白
find('>span')
做了什么

你能解释一下吗

HTML代码

<button>Ibis<span class="bg"><span>Ibis</span></span></button>
$(this).find('> span').animate( { width: '100%' } );
$(this).find('>span')

查找此

在您的示例中,它查找
,但不查找该
中的

Jquery选择器的工作原理与CSS选择器非常相似。这就像在CSS中编写
按钮>span
。这只会给你直接的子跨度。如果没有
,这就像在CSS中编写
按钮span
,这将影响
中的所有跨度


HTH:)欢迎使用StackOverflow

您可以使用
.children('span')
重写此文件,这可能会使以后的阅读更容易@杰克,谢谢你。我明白你的意思了,谢谢!很好的解释。