Problem adding events to Datatables DOM

Problem adding events to Datatables DOM

diego30kdiego30k Posts: 5Questions: 0Answers: 0
edited June 2012 in General
Hi everybody, I've created and populated my datatable using this code:

[code]
function getListaAlbums(){
$.ajax({
data: {
operacion: "listarTodos"
},
type: "POST",
dataType: "JSON",
url: "albumBL.php",
success: function(resp){
listtable.fnClearTable();
$.each(resp,function(i) {
listtable.fnAddData([
resp[i].id,
resp[i].album,
resp[i].artista,
resp[i].annio,
resp[i].calificacion,
"Update"
]);

});
}
});
[/code]

Now I try to add a click event to all my "Update" links generated using this code:

[code]
$("a.updateLink").on("click",function(event){
//My code goes here
});
[/code]

As you can imagine, my event code doesn't work. Does anybody know a solution?

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Use a delegate event ( http://datatables.net/faqs#events ):

    [code]
    $(document).on("click", "a.updateLink", function(event){
    //My code goes here
    });
    [/code]

    Allan
This discussion has been closed.