Thanks Andrea, Gordon and Klaus All your suggestions worked fine in the example HTML I posted. I need to do a bit of fine-tuning for my actual app so I might be back!
Paul On 8 Feb, 14:30, Klaus Hartl <[EMAIL PROTECTED]> wrote: > Because tds will be stored in order of appearance in the DOM - maybe > we can speed up that query by matching the td as a sum of cells in a > row and its position: > > $('#myTable td:eq(1)'); // 2nd cell, 1st row > $('#myTable td:eq(6)'); // 2nd cell, 2nd row > $('#myTable td:eq(11)'); // 2nd cell, 3rd row > > => cellPosition + rowPosition * numberOfCells > > Would need to be tested if it really performs better. I could imagine > that for huge data tables. > > By the way: the index for eq is zero-based, thus to match the second > cell you need eq(1) and so on... > > --Klaus > > On Feb 8, 2:20 pm, Gordon Roman <[EMAIL PROTECTED]> wrote: > > > Somthing Like This > > > $(document).ready(function(){ > > $('#btn').click(function (){ > > alert($("#myTable tr:eq(1) td:eq(2)").html()); > > }); > > > }); > > paulj wrote: > > > In JavaScript, getElementById('myTable').rows[1].cells[2] would select > > > the cell that is in 2nd row of the 3rd column. > > > What is the jQ equivalent of this? (or maybe jQ has a different and > > > better way of doing this?) > > > > This is some HTML markup using the JS method : > > > > <html> > > > <head> > > > > <script type = "text/javascript" src="jquery.js"></script> > > > > <script type="text/javascript"> > > > > $(document).ready(function() > > > { > > > $('#btn').click(function () > > > { > > > var cell=document.getElementById('myTable').rows[1].cells[2] > > > alert(cell.innerHTML)}) // displays 'g correct!' > > > }); > > > > </script> > > > > </head> > > > > <body> > > > <table id="myTable" border="1"> > > > <tr> > > > <td>a</td> > > > <td>b</td> > > > <td>c</td> > > > <td>d</td> > > > </tr> > > > > <tr> > > > <td>e</td> > > > <td>f</td> > > > <td>g correct!</td> <!-- this is the cell selected by > > > > document.getElementById('myTable').rows[1].cells[2] --> > > > <td>h</td> > > > </tr> > > > > </table> > > > > <br /> > > > <input type="button" id='btn' value="Display contents of selected > > > cell"> > > > </body> > > > </html> > > > > TIA