I have an HTML table where I need to select multiple rows and send first cell value of each row to a function. I tried the follwing code. This selects only one row and sends only one value to the function. If I select multiple rows only the first value selected is entering the function. How do I solve this issue?
test.html
<table id="table">
<tr>
<td>1 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
</tr>
<tr>
<td>2 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
</tr>
<tr>
<td>3 Ferrari F138</td>
<td>1 000€</td>
<td>1 200€</td>
</tr>
</table>
<input type="button" class="ok" id="tst" value="OK" onclick="" />
test.js
$("#table tr").click(function(){
$(this).addClass('selected').siblings().removeClass('selected');
var value=$(this).find('td:first').html();
alert(value);
});
$('.ok').on('click', function(e){
var selectedID=$("#table tr.selected td:first").html();
fnMatchID(selectedID);
});
function fnMatchID(selectID){
//some code here
}
DEMO :::: JSFiddle
I need to select multiple rows and send all the first cell values of the selected rows to a function.