I'm trying to create a new tr element and set it's id attribute to the last id in the table of my MySQL db.
Here's what I have, but this does not set the id properly:
$('<tr>').html(response)
.attr('id',function(){
var daId;
$.get(
'/getlastid.php',
null,
function(response){
daId = response;
alert(daId); //this shows correct id from db
});
return daId;
})
.prependTo('#table-id tbody'); //the tr does not have the id attribute set
How can I get this working right? The alert proves that my server side code is correct, it's just that the id attribute is not being created for the new row.