I'm creating a registration page where the user can register several other people. I've made it so that the table only shows if the user selects a certain option. I've also added the add button and that adds rows perfectly fine. The problem is when I add the function for the delete button everything breaks. Here's my html:
<div id="add_table" style="display:none;" >
<button type="button" id="AddLine">Add Line</button>
<table border="1px" id="table">
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Phone</td>
<td>Email</td>
<td>Ethnicity</td>
</tr>
<tr>
<td><input type=text /></td>
<td><input type=text /></td>
<td><input type=text /></td>
<td><input type=text /></td>
<td><input type=text /></td>
<td><button type="button">delete</button></td>
</tr>
</table>
</div>
And here's my jquery code:
$(document).ready(function(e) {
$("input[name= 'Reg_num_r']").change( function () {
if($(this).val()==1) {
$("#add_table").hide();
} else {
$("#add_table").show();
}
});
/*$("#table").on("click", "button", function() {
$(this).closest("tr").remove();
});*/
$("#AddLine").click(function () {
var row = "<tr><td><input type=text /></td><td><input type=text /></td><td><input type=text /></td><td> <input type=text /></td><td><input type=text /></td><td><button type=button>delete</button></td></tr>";
$("#table").append(row);
});
});
Now when I uncomment the commented code above, everything stops working. The table just doesn't show up even if the user selects the right option. How should I fix it so it properly executes the delete row operation?