What is the best (most productive, less CPU-loading) way to select certain children from ancestor with jQuery?
Let's imagine that we have:
<div>
<b>1</b>
<p>2</p>
<a>3</a>
<p>2</p>
</div>
So
$('div > p')
or
$('div').children('p')
?
According to this jsPerf test I just created $('div > p')
is about twice as fast. I don't think the two selectors differ in the elements they get back, so the first one may be more desirable, at least from a performance point of view.
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