JQuery children selector explanation
I have this markup
<div id="parent">
    <div class="child"></div>
    <div class="child"></div>
</div>
When I select child with jQuery, there are two ways:
$("#parent .child")
and
$("#parent").find(".child")
Can someone explain the difference between the two selectors and which one is better?
+4
user5423386 
source
share2 answers
$("#parent .child")and $("#parent").find(".child")match. Both will select all children with the class name childrecursively. those. it returns children of any level.
If you use $("#parent > .child"), it will only return first level children. This selector is the same as$("#parent").children(".child")
0