jQuery的空间​​和>选择器? [英] What is the difference between jQuery's space and > selectors?

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

问题描述

空间> selectors?可能是相关的,我怎么能找到另一个东西的直接子,而不是降低后代行?

What's the difference between the space and > selectors? And possibly related, how can I look for something that's the direct child of something else, and not lower down the descendant line?

推荐答案

For:

<ul>
  <li>Item 1</li>
  <li>Item 2
    <ul>
      <li>Item 2.1</li>
      <li>Item 2.2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

例如

$("ul > li").addClass("blah");

将类blah添加到1 2和3,而:

adds class "blah" to 1 2 and 3 whereas:

$("ul li").addClass("blah");

向每个列表元素添加类blah。

add class "blah" to every list element.

我不确定您所指的是<和?运算符。

I'm not sure what you're referring to with < and ? operators.

这篇关于jQuery的空间​​和&gt;选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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