#10960 closed enhancement (invalid)
jQuery :first takes 5 times as long as el.eq(0)
Reported by: | 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.
Change History (2)
comment:1 Changed 11 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 11 years ago by
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.
Note: See
TracTickets for help on using
tickets.
Wrong place. Try asking in the forums, or on StackOverflow.