+ 3

jQuery Selectors

i'm a little bit confused with parent > child thing please help me figure this out! parent > child $("div > p") all <p> elements that are a direct child of a <div> element what does this mean?

9th Aug 2017, 6:32 PM
Mohammad Moallemi
Mohammad Moallemi - avatar
7 Answers
+ 9
It is very similar but there is a small and important difference between them, i recommend to read this thread, especially the second most voted answer..! [ ...A space selector will select all deep descendants whereas a greater than > selector will only select all immediate descendants. ] https://stackoverflow.com/questions/4459821/css-selector-what-is-it
9th Aug 2017, 10:15 PM
Maz
Maz - avatar
+ 9
That means exactly what's written in. <div> <!-- father --> <p></p> <!-- child --> <p></p> <!-- child --> </div> In this case you're going to select <p> elements inside the <div> element.
9th Aug 2017, 8:51 PM
Maz
Maz - avatar
+ 3
tnQ so much it helped me a lot
9th Aug 2017, 10:44 PM
Mohammad Moallemi
Mohammad Moallemi - avatar
+ 2
isn't this same with the $("div p") ??? it selects all the p elements inside the div element
9th Aug 2017, 9:06 PM
Mohammad Moallemi
Mohammad Moallemi - avatar
0
The div element contains p so p child div
23rd Nov 2019, 6:01 PM
Hacker Lightning
Hacker Lightning - avatar
0
let's just say <div> is a father then he as like 4 children that is <div> <!- father -> <p></p> <!- child -> <p></p> <!- child -> <p></p> <!- child -> <p></p> <!- child -> </div> then you can select any of the child or all
4th Jan 2020, 3:42 AM
Stephen Olatunji
Stephen Olatunji - avatar
- 1
Hello
11th Sep 2020, 3:50 PM
Muhammad Hilal Fadhila
Muhammad Hilal Fadhila - avatar