Search code examples
jqueryhtml-tabletraversal

Get data from above cell


I need to retrieve the bottom border width of the cell above the clicked cell.

var $this = $(this);
var col = $this.parent().children().index($this);
var row = $this.parent().parent().children().index($this.parent());
var bordWidth= ($this.parents('tr:eq('+(row-1)+')').find('td:eq('+col+')').css("border-bottom-width"));

Solution

  • Try this.

    var $this = $(this);
    var $tr = $this.parent();
    var col = $tr.children().index($this);
    var bordWidth = $tr.prev().children().eq(col).css("border-bottom-width");
    

    .prev() will get the previous tr element and then using .children() get all the td's and get the required td using eq() method.