Faster jquery selector for finding a number of TD elements
Posted
by Bernard Chen
on Stack Overflow
See other posts from Stack Overflow
or by Bernard Chen
Published on 2010-03-31T21:43:29Z
Indexed on
2010/03/31
21:53 UTC
Read the original article
Hit count: 330
I have a table where each row has 13 TD elements. I want to show and hide the first 10 of them when I toggle a link. These 10 TD elements all have an IDs with the prefix "foo" and a two digit number for its position (e.g., "foo01"). What's the fastest way to select them across the entire table?
$("td:nth-child(-n+10)")
or
$("td[id^=foo]")
or is it worth concatenating all of the ids?
$("#foo01, #foo02, #foo03, #foo04, #foo05, #foo06, #foo07, #foo08, #foo09, #foo10")
Is there another approach I should be considering as well?
© Stack Overflow or respective owner