I have HTML table where I need to select a row and send its first cell ID to a button and onclick
of the button send the selected value to a function in Javascr
check http://jsfiddle.net/Z22NU/12/
function fnselect(){
alert($("tr.selected td:first" ).html());
}
You can access the first element adding the following code to the highlight
function
$(this).find(".selected td:first").html()
Working Code:JSFIDDLE
In my case $(document).ready(function() was missing. Try this.
$(document).ready(function(){
("#table tr").click(function(){
$(this).addClass('selected').siblings().removeClass('selected');
var value=$(this).find('td:first').html();
alert(value);
});
$('.ok').on('click', function(e){
alert($("#table tr.selected td:first").html());
});
});
This below code will give selected row, you can parse the values from it and send to the AJAX call.
$(".selected").click(function () {
var row = $(this).parent().parent().parent().html();
});
$("#table tr").click(function(){
$(this).addClass('selected').siblings().removeClass('selected');
var value=$(this).find('td:first').html();
alert(value);
});
$('.ok').on('click', function(e){
alert($("#table tr.selected td:first").html());
});
Demo:
http://jsfiddle.net/65JPw/2/