What is the difference between jQuery's space and > selectors?

后端 未结 4 1140
日久生厌
日久生厌 2021-02-08 07:48

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 d

4条回答
  •  [愿得一人]
    2021-02-08 08:53

    For:

    • Item 1
    • Item 2
      • Item 2.1
      • Item 2.2
    • Item 3

    For example

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

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

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

    add class "blah" to every list element.

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

提交回复
热议问题