jQuery Selectors | SoloLearn: Learn to code for FREE!


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?

8/9/2017 6:32:24 PM


7 Answers

New Answer


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


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.


tnQ so much it helped me a lot


isn't this same with the $("div p") ??? it selects all the p elements inside the div element


The div element contains p so p child div


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