I want to add highlight class on selected row in ajax table while clicking edit button. I don’t know why my code is not working. Could you help me? Thanks in advance.
function getData(){
$.ajax({
url:"<?php echo base_url(); ?>copycontrol/getData",
method:"post",
dataType: "json",
success:function(data){
var html='';
var i;
var count= 1;
html+='<table id="copyTable" class="table table-bordered"><tr><th class="border_none"style="width:2%"></th><th class="border_none" style="width:86%">Procedure Description</th><th class="text-center" style="width:12%">Operations</th></tr>';
for(i in data){
html+='<tr><td>'+count+'</td><td onclick="copy(this)">'+data[i].name+'</td><td><button type="button" class="delete" id='+data[i].id+'><i class="fa fa-trash" title="Delete" style="font-size:20px;"></i></button><button type="button" class="edit" title="Edit" id='+data[i].id+'><i class="fa fa-edit" style="font-size:20px;"></i></button></td></tr>';
count++;
}
html+='</table>';
$('#showData').html(html);
}
});
}
$(document).on('click', '.edit', function(){
var eID = $(this).attr("id");
$('#copy_info').text("Edit row.");
$.ajax({
url:"<?php echo base_url(); ?>copycontrol/fetchSingleData",
method:"post",
data:{eID: eID},
dataType:"json",
success:function(data){
var i;
for(i in data){
$('#name').val(data[i].name);
}
$('#single').val(eID);
$('#submit').text("Edit");
$('#submit').val("update");
$('#name').focus();
var selectedRow = $(this).closest('tr').find("td:eq(0)").text();
$("tr:nth-child(" + selectedRow + ") ").addClass('highlight');
if($('#submit').val() == "submit")
{
$('#success').text("Row data was successfuly edited.");
$('#success').fadeOut(3000);
}
}
});
});
This code produces error: “Uncaught Error: Syntax error, unrecognized expression: :nth-child()…”
var selectedRow = $(this).closest('tr').find("td:eq(0)").text();
$("tr:nth-child(" + selectedRow + ") ").addClass('highlight');