Cracker0dks
Cracker0dks

Reputation: 2490

Dynamic event binding not firing

I want to bind a tr click event to my datatable.

This is my code now:

$(myDataTable).find("tbody tr").on("click", function (e) {
//do the magic
});

It works for the first page. On second page i got no click event.

.live and .delegate also not work.

Anyone with a solution and can say why this is not working? I would prefer not to use the dataTables render callbacks.

Upvotes: 1

Views: 49

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115222

To work with dynamic element use the following code

$(myDataTable).on("click","tbody tr", function (e) {
//do the magic
});

Documentation : http://api.jquery.com/on/

Upvotes: 1

Anton
Anton

Reputation: 32581

To bind to dynamic elements you must do this

$(myDataTable).on("click","tbody tr", function (e) {
//do the magic
});

.on( events [, selector ] [, data ], handler(eventObject) )

Documentation

Upvotes: 1

Related Questions