tr
is not directly inside table
, even though it looks like that from your markup. Every row is put inside a thead
, tbody
or tfoot
element, and if you omit the <tbody>
start tag, the browser will insert it silently for you. So to select the row you'd have to say:
table>tbody>tr
This is due to a quirk of HTML parsing where start-tags are allowed to be omitted in many cases (eg. if you omit <body>
, the browser will assume it was there the first time it meets some page content).
However, XHTML has more regular parsing rules, and an upshot of that is that if the page is parsed in XML mode, there will be no implied tbody
. So it's more difficult to write a selector that will match in both cases.
Also, the nth
selector is a non-standard jQuery extension to Selectors which will cause the slow JavaScript ‘Sizzle’ selector engine to be used instead of the browser's fast built-in selector engine (where available, ie. not IE6-7). Try to stick to standard CSS Selectors to avoid this.
You are best off avoiding both problems by using DOM-style traversal instead of selectors to get the element you want. DOM itself offers the rows
and cells
lists on tables and rows, which is probably easier than anything jQuery offers:
var table= $('#someselector table').get(0); // however you access the table
var cell= table.rows[0].cells[0]; // or whatever rows/column you want
$(cell).doSomething(); // ...