On Aug 4, 2007, at 12:20 AM, Ganeshji Marwaha wrote:
ha ha, u got me...
:-)
but, why is that so? aren't there 3 td's each in a "tr"
representing index 2?
Yes, there are three td's, each representing index 2, but only within
their respective context. When you have $("tr:eq(1), td:eq(2)") ,
you are combining two separate selectors, one for $('tr:eq(1)') and
one for $('td:eq(2)'). It's the same as doing this: $('tr:eq(1)').add
('td:eq(2)'). So, what you're saying is, "give me the second table
row and give me the third table cell." Notice that the second
selector has no context.
If you wanted to select all 3 td elements representing index 2 (let's
forget about the tr for the moment), you need to say something like,
"give me the every table cell with index 2 within the context of each
table row" :
either:
$('td:eq(2)', 'tr')
or:
$('tr').find('td:eq(2)')
Or you could say, "give me all table cells that are the 3rd child of
their parent":
$('td:nth-child(3)')
Hope that makes sense.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Aug 4, 2007, at 12:20 AM, Ganeshji Marwaha wrote:
ha ha, u got me...
but, why is that so? aren't there 3 td's each in a "tr"
representing index 2?
-GTG
On 8/3/07, Karl Swedberg <[EMAIL PROTECTED]> wrote:
On Aug 3, 2007, at 6:15 PM, Ganeshji Marwaha wrote:
I don't think ur selector is right for selecting the 2nd row, 3rd
column.
It most probably is returning you more elements depending on the
number of rows u have.
Eg: if you have 3 rows in your table, then it should return, 1 tr
and 3 td's each representing the 3rd column in every row.
I don't think that is quite right either, Ganeshji.
Matt's selector ...
$("tr:eq(1), td:eq(2)")
... will select exactly one row (the second one) and exactly one
cell (the third one).
To return "1 tr and 3 td's each representing the 3rd column in
every row," he'd have to do something like this ...
$("tr:eq(1), td:nth-child(3)")
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com