Reputation: 12400
In jquery, say I have an html selector select. Which is faster to get the ith element from the selector? If one is faster, how much faster? By a little or a lot?
select.children[i]
Or
$j('*:nth-child(' + i + ')', select)
Upvotes: 1
Views: 5676
Reputation: 25776
select.children[i]
is way faster. This is because it doesn't have the overhead of jQuery. Here's a jsPerf, where you can see the results.
For the first test i used
var select = document.getElementById('select');
var option = select.children[2];
And the second
var select = document.getElementById('select');
var option = $('*:nth-child(' + 2 + ')', select);
Upvotes: 2