UPDATE 1:
I am wondering if it has anything related to the fact that the button is inside the element that is being removed, so it will delete the button which will also delete? Perhaps this is not a problem, I just typed the text that I think of.
I just tried:
$( "input.btnX" ).click(function(event) { alert("test"); });
and I donβt get a warning ... Should I use live or is it on now because the buttons along with the table are dynamically generated.
ORIGINAL QUESTION:
I have a table (dynamically generated, so I don't know how many tr it has in tbody, which looks something like this:
<table> <tbody> <tr> <td>col1</td> <td>col2</td> <td><input type="button" class="btnX" name="x" value="x" /></td> </tr> <tr> <td>col1</td> <td>col2</td> <td><input type="button" class="btnX" name="x" value="x" /></td> </tr> </tbody> </table>
How to remove parent tr if x button is pressed? Therefore, in this example, if you click the bottom x, it should remove the bottom tr.
I tried this:
$( "input.btnX" ).click(function(event) { $(this).parent('tr').remove(); });
But nothing happens.
source share