I heard, that second syntax is much faster. Is it right?
$('div *')
or
$('div').find('*')
Or both take equal time?
EDIT:
Ok, downvoters, lets see this TEST (thanks to @AlienWebguy). Can anybody explain?
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.
Exact results may depend upon the page HTML and specific selector query, but this jsperf says that the
$('div').find('*')is way, way slower than$('div *')in the HTML case I picked.For a question like this to be meaningful, you have to specify an exact selector and a body of HTML that you’re going to run it against.
Now that you’ve added a test that uses some specific HTML (but a different selector), I thought I’d run your HTML from that test against the actual selectors you asked about in a test that actually tests what you asked about. In Chrome 13, I find the
$('div *')selector to be 9 times faster than$('div').find('*')when run against the HTML in your test. You can see the jsperf here.