Here is my code:
$(document).ready(function(){
$("#add_tactic").click(function(){
var i = ($('#tactic_commentary tr').length-3)/2+1;
$("#tactic_commentary tr").eq(-1).before('<tr><td style="width: 180px"><div id="form_label">Tactic Name:</div></td><td style="width: 575px" class="auto-style1"><input maxlength="150" name="tactiname'+i+'" style="width: 565px" type="text" /></td></tr>');
$("#tactic_commentary tr").eq(-1).before('<tr><td style="width: 180px"><div id="form_label" class="auto-style1">Tactic Description:</div></td><td style="width: 575px" class="auto-style1"><textarea name="tacticdescription'+i+'"></textarea></td></tr>');
});
});
My #add_tactic is as follows:
<div id="add_tactic">Add Tactic</div>
when this page loads, the on click event works fine. If the dropdown in the form changes, it replaces the DIV container with a rebuilt form dependent on your choice. The on click function of add_tactic does not work when the table is reloaded. Table ID does not change. Is there something I have to do when removing an element so that events are bound to it when it returns?