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')
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.