类选择器中的jQuery类 [英] jQuery class within class selector

查看:73
本文介绍了类选择器中的jQuery类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="outer">
     <div class="inner"></div>
</div>

如何在此处找到内部div?

how do I find the inner div here?

$container.find('.outer .inner')

只是要使用class="outer inner"查找div,对吗?

is just going to look for a div with class="outer inner", is that correct?

所以我尝试了

$container.find('.outer > .inner')

但这似乎不起作用.

我知道用

$container.find('.outer').find('.inner')

但我正在寻找一种读起来更好的恕我直言的单选择器语法.

but I'm looking for the kind of single selector syntax which reads better imho.

推荐答案

只是要查找class ="outer inner"的div,对吗?

is just going to look for a div with class="outer inner", is that correct?

否,'.outer .inner'将查找具有 .inner 类的所有元素,这些元素也具有具有 .outer 类的元素作为祖先. '.outer.inner'(无空格)会给出您正在考虑的结果.

No, '.outer .inner' will look for all elements with the .inner class that also have an element with the .outer class as an ancestor. '.outer.inner' (no space) would give the results you're thinking of.

'.outer > .inner'将为 .inner 类的元素查找具有 .outer 类的元素的直接子元素.

'.outer > .inner' will look for immediate children of an element with the .outer class for elements with the .inner class.

'.outer .inner''.outer > .inner'都应适用于您的示例,尽管选择器在本质上是不同的,并且您应该对此保持警惕.

Both '.outer .inner' and '.outer > .inner' should work for your example, although the selectors are fundamentally different and you should be wary of this.

这篇关于类选择器中的jQuery类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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