Skip to main content

Bug Tracker

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: Owned by:
Priority: low Milestone: None
Component: selector Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

I'm doing some research, and I wonder why is the following:

The following source takes 600ms

var d1 = new Date;
var t = $("table");
    var f = t.find("td").eq(0);
console.log((new Date) - d1);

But then I change this:

var f = t.find("td:first");
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 sindresorhus comment:1

component: unfiledselector
priority: undecidedlow
resolution: → invalid
status: newclosed

Wrong place. Try asking in the forums, or on StackOverflow.

Changed December 06, 2011 02:29PM UTC by timmywil 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.