If the table is really big it might be better to use event delegation:

$('table').click(function(e){
  var $td = $(e.target).closest('td'),
      $tr = $td.parent(),
      pos = $tr.children().index($td),
      $up = $tr.prev().children().eq(pos),
      $dn = $tr.next().children().eq(pos);
  $up.css("background-color", "red");
  $dn.css("background-color", "blue");
});

Reply via email to