I want to add an inner table to table cell using JavaScript. The adding of next table data is not working and it looks the browser automatically closes the inner table . the next data cell is showing only when I removes the </table> of the inner table from the code but it is not properly arranged (Goes to next row). Can anybody help me with this one please.....
CODE:
$.each(result, function(i, data){
$('#body').append(
'<tr id="#tr'+data['id']+'"><td>'+(i+1)+'</td>'+ //Adding new row
'<td>'+data['code']+'</td>'+
'<td>'+data['dscr']+
'<div class="table-dscr">'+ //Inserting inner table
'<table id="'+data['id']+'">'+ '<tr><th>Unit</th><th>Price</th><th>Qty</th></tr>');
$.each(data, function(j, meta){ //Inserting rows of inner table
if (typeof meta['unit'] != 'undefined') {
$('#'+data['id']).append('<tr>'+
'<td>'+meta['unit']+'</td>'+
'<td>'+meta['price']+'</td>'+
'<td>'+meta['qty']+'</td>'+
'</tr>Hello ');
}
});
$('#body').append(
'</table></div></td>'+ //Closing inner table
'<td class="table-btn">'+ //Adding next table data
'<a href="additem.php?edit_id='+data['id']+'">Edit</a>'+
'<a href="viewstock.php?delete_id='+data['id']+'">Delete</a>'+
'</td></tr>');
});
I altered the code and added this part. But it is not affecting the table. the id is added dynamically..
$('#tr'+data['id']).append(
'<td class="table-btn">'+
'<a href="additem.php?edit_id='+data['id']+'">Edit</a>'+
'<a href="viewstock.php?delete_id='+data['id']+'">Delete</a>'+
'</td></tr>'
);