I am a bit confused between these 2 selectors.
Does the descendent selector:
div p
select all p
within a div
whether or not it's an immediate descedent? So if the p
is inside another div
it will still be selected?
Then the child selector:
div > p
Whats the difference? Does a child mean immediate child? Eg.
<div><p>
vs
<div><div><p>
will both be selected, or not?
Descendant Selector :The descendant Selector selects all child elements of the selected parent element. In this example, the descendant selector selects all li of selected ul elements. 2. Direct Child Selector : This selector selects only the direct child of the selected element.
Difference between Descendant and Child SelectorsDescendant selector is select child of child of so forth child element where else Child selector is only of that child of specific element.
The descendant selector is a way to select elements that are located somewhere underneath other elements, according to the tree structure of the webpage. This selector is actually multiple selectors combined together, but separated by a space.
The CSS child selector is used to select all child elements with a particular parent element.
Just think of what the words "child" and "descendant" mean in English:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With