Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  104] [ 2]  / answers: 1 / hits: 9660  / 11 Years ago, mon, january 27, 2014, 12:00:00

I am trying to extract the td values belonging a td rowspan.



<!DOCTYPE html>
<html>
<body>
<table border=1>
<tr>
<th>Month</th>
<th>Expenses</th>
<th>Exp/ Divided</th>
</tr>
<tr>
<td rowspan=2>January</td>
<td rowspan=2>$100</td>
<td>$50</td>
</tr>
<tr>
<td>$50</td>
</tr>
<tr>
<td rowspan=3>February</td>
<td rowspan=3>$400</td>
<td>$150</td>
</tr>
<tr>
<td>$150</td>
</tr>
<tr>
<td>$100</td>
<tr></tr>
</table>
</body>
</html>


So if I click on January for example I have to extract its divided expenses: $50, $50



if I click on February I have to extract its divided expenses: $150, $150, $100


More From » jquery

 Answers
2

Try this,



$(function(){
$('.rowspan').on('click',function(){
$tr=$(this).closest('tr');
rowspan=$(this).attr('rowspan');
index=$('tr').index($tr);
tot=parseInt(index)+parseInt(rowspan);
for(var i=index,len=tot;i<len;i++){
console.log($('tr:eq('+i+') td:last').text());
}
});
});


Working Demo


[#48329] Saturday, January 25, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reesel

Total Points: 345
Total Questions: 124
Total Answers: 119

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;