DocumentThe CSS selector syntax contains a greater sign and is also referenced in the jQuery selector syntax. I have never specifically figured out the difference between this selector and the space selector. Here is a small example to learn about it, because jQuery and CSS have similar syntax in this part, therefore, jQuery is directly used to explain the problem, which is more intuitive.
Let's take a look at the example. The structure is very simple:
Reference content is as follows: <Div id = "test"> <div> a </div> <div> B </div> <div> c </div> <div> <div> d </div> <div> e </div>, we can execute the following two statements: Alert ($ ('# test> div'). length ); Alert ($ ('# test div'). length ); |
The first statement uses a greater than the number selector to search for the div element in the first child element of # test. In this example, the result is 2.
The second statement uses a space selector to search for the div element in all sub-elements of # test. In this example, 7 is returned, it includes two subelements of the first level and five subelements of the second level.
Is that simple, do you understand? You are welcome to continue reading other articles from the Institute.