- $("table#summary tr:nth-child("+k+")")
So I cranked on the Firebug profiler and profiled the function that does the heavy lifting. Calls to nth-child were taking up 4700ms out of about 5000ms total!
After staring at it for a minute, I recalled that :nth-child looks for all elements that are the nth child of their parent -- that's what I want, right? -- but it does not assume that they are direct descendants of the preceding element in the selection chain.
"Matches all elements that are the nth-child of their parent ... While :eq(index) matches only a single element, this matches more than one ..."This is certainly what you need in some cases, but if your jquery consists of a set of siblings and you just want to grab a particular element by index, it's far quicker to do one of the following:
- $("table#summary tr:eq("+k+")")
- $("table#summary tr").eq(k)