Side navigation
#10960 closed enhancement (invalid)
Opened December 06, 2011 10:41AM UTC
Closed December 06, 2011 10:51AM UTC
Last modified December 06, 2011 02:29PM UTC
jQuery :first takes 5 times as long as el.eq(0)
Reported by: | tsukasa1989@gmail.com | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | selector | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I'm doing some research, and I wonder why is the following:
The following source takes 600ms
var d1 = new Date; var t = $("table"); for(i=0;i<10000;i++) { var f = t.find("td").eq(0); } console.log((new Date) - d1);
But then I change this:
var f = t.find("td:first"); or var f = t.find("td:eq(0)");
Which takes 4000ms (it's x5!)
Though :first-child only takes 600ms and is the fastest.
Now I wonder, can't :first or :eq(0) be made faster, cu's this is insane. If I just select all elements and do a eq(0) after, it is way faster.
Attachments (0)
Change History (2)
Changed December 06, 2011 10:51AM UTC by comment:1
component: | unfiled → selector |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Changed December 06, 2011 02:29PM UTC by comment:2
The answer is that :first is a custom jQuery selector that does not use querySelectorAll. It is there for convenience, but we recommend using the faster native selectors.
Wrong place. Try asking in the forums, or on StackOverflow.