7

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")); 
3
  • 1
    I typed the answer in your previous question, but you deleted it before I was able to post it. Instead of posting a new question, edit the original question instead, to include the new details. Commented Feb 11, 2012 at 16:55
  • I think this thread should answer your question. Commented Feb 11, 2012 at 17:03
  • @RobW- Sorry about that. My previous question was too broad and was turing out to be 10 questions instead of one. Commented Feb 11, 2012 at 18:52

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Keep in mind that this won't work if there are colSpan > 1 set on the previous tr. This is the case when you are at cell 2 of row 2 and the previous cell has only one cell with colSpan of 2. In this case eq(col) would return an empty selector for the previous row.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.