JQuery - Remove Parent Table Row on Button Click Event Example

11-Apr-2023

.

Admin

JQuery - Remove Parent Table Row on Button Click Event Example

Now let's see example of how to delete parent table row onclick event in jquery. We will show remove parent tr using button click event in js. i will give you two example for remove table row on button click in jquery.

If you have issue with remove table row and click event not working then here is solution. we will use on with click event on button td.

We will remove parent table row using two way. first we will use parents() and another is closest(). So basically you can see both example. it will help you any one.

Example 1 :


<!DOCTYPE html>

<html>

<head>

<title>Jquery - Remove Parent Table Row on Button Click Event - NiceSnippets.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

</head>

<body>

<table>

<tr>

<th>ID</th>

<th>Name</th>

<th>Email</th>

<th>Action</th>

</tr>

<tr>

<td>1</td>

<td>Test</td>

<td>test@test.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

<tr>

<td>2</td>

<td>Demo</td>

<td>demo@demo.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

<tr>

<td>3</td>

<td>Test Demo</td>

<td>testdemo@testdemo.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

</table>

<script type="text/javascript">

$(document).ready(function () {

$("body").on("click", ".btn-remove", function(){

$(this).closest('tr').remove();

});

});

</script>

</body>

</html>

Example 2 :

<!DOCTYPE html>

<html>

<head>

<title>Jquery - Remove Parent Table Row on Button Click Event - NiceSnippets.com</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

</head>

<body>

<table>

<tr>

<th>ID</th>

<th>Name</th>

<th>Email</th>

<th>Action</th>

</tr>

<tr>

<td>1</td>

<td>Test</td>

<td>test@test.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

<tr>

<td>2</td>

<td>Demo</td>

<td>demo@demo.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

<tr>

<td>3</td>

<td>Test Demo</td>

<td>testdemo@testdemo.com</td>

<td><button class="btn-remove">Remove</button></td>

</tr>

</table>

<script type="text/javascript">

$(document).ready(function () {

$("body").on("click", ".btn-remove", function(){

$(this).parents('tr').remove();

});

});

</script>

</body>

</html>

It will help you....

#Jquery