Fuxi
Fuxi

Reputation: 7599

Defining array index in a jQuery selector

I have several tables in my HTML markup which don't have any attributes and I'm wondering: is it possible to define a jQuery selector which directly picks eg. the third table?

Upvotes: 2

Views: 697

Answers (2)

Nick Craver
Nick Craver

Reputation: 630569

In addition to Tim's answer, there's a :eq() version you can use inside a selector as well, for example:

$("#myContainer table:eq(2) tr")

Upvotes: 1

Tim
Tim

Reputation: 9489

yeah you can use eq from jquery

$('table').eq(2).css('background-color', 'red'); for example this gets the third table (zero-based counting, jquery starts counting with zero therefor eq(2)) and give it a red background color.

Upvotes: 1

Related Questions