Reputation: 4067
I am using html grid.I want to get the index values of columns that has class named selected . To understand it better i will give the html grid format
<table style="width:600px;height:200px" id="gdTable" border="1">
<tr>
<td>
<span id="lblFinance">Finance</span>
</td>
<td>
<span id="lblRow1">r1c1</span>
</td>
</tr>
<tr>
<td>
<span id="Label1">Finance1</span>
</td>
<td **class="selected"**>
<span id="Label2">r2c1</span>
</td>
</tr>
<tr>
<td **class="selected"**>
<span id="Label7">Finance2</span>
</td>
<td>
<span id="Label8">r3c1</span>
</td>
</tr>
</table>
The result i wanted is 2(index of the col in second row)+1(index of col in third row)=3
The jquery i have attempted is given below.I have tried to alert the column index but not getting the desired result.
function getCellValue() {
$("#gdTable tr").each(function () {
if($(this).children().hasClass("selected")){
var selCOL = $(this).children().hasClass("selected");
alert($(this).index(selCOL));
}
})
}
Upvotes: 2
Views: 1955
Reputation: 15699
Try:
getCellValue();
function getCellValue() {
$("#gdTable tr td.selected").each(function () {
alert($(this).index());
});
}
Upvotes: 3