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

Reply via email to