Devin Burke Devin Burke - 1 year ago 108
jQuery Question

jQuery: Get next table cell vertically

How can I use jQuery to access the cell (

) immediately below a given cell in a traditional grid-layout html
(i.e., one in which all cells span exactly one row and column)?

I know that the following will set
to the cell to the immediate right of the clicked cell because they are immediate siblings, but I am trying to retrieve the cell immediately below the clicked cell:

$('td').click(function () {
var nextCell = $(this).next('td');

Preferably I would like to do it without any use of classes or ids.

Answer Source

Try this:

  // cache $(this);
  var $this = $(this);

  // First, get the index of the td.
  var cellIndex = $this.index();

  // next, get the cell in the next row that has
  // the same index.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download