[jQuery] What is the easiest way to add events to dynamically added rows?
What is the easiest way to add events to dynamically added rows? I
can't seem to get .toggle() to react to the newly added rows.
For example:
var html = [];
...
$.each(json, function(i,data){
var row = '<tr id="interview' + i + '"><td>data.test</td></tr>';
html.push(row);
}
$("#dataTableBody").append(html.join(""));
$("#dataTableBody tr").toggle(
function () {
alert("toggled on");
}
function () {
alert("toggled off");
}
);
If you have any suggestions, outside of my initial question, on how to
make this code better, I'm all ears. :)