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

后端 未结 4 1142
日久生厌
日久生厌 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:35

    As already mentioned, a space will select any descendant, whereas > will select only immediate children. If you want to select only grandchildren or great-grandchildren, then you could use this:

    #foo > * > * > .bar
    

    (all elements with class "bar" which are great grandchildren of the element with id "foo")

提交回复
热议问题