3

I'm using datatables plugin for jquery to show my data on the page. I have this selector when someone clicks on a row:

$('#myTable tr[class !="tableHeader"]').click(function(){

    alert("clicked!");

}

and everything is OK until I click on the "Next page" which shows me next 10 results - then this click function doesn't show "clicked" message box anymore no matter which row I click.

I'm guessing that the problem is in a way how these new results (rows in the table) are shown, so please give me some ideas on how to solve this.

1 Answer 1

7

Use jQuery's Live function. Live will apply to all elements on the page, even ones that don't exist yet (I assume this is your issue). Thus, your new rows will be clickable when they are created and added to the DOM.

$('#myTable tr[class !="tableHeader"]').live('click', function() {
  alert("clicked!");
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.