Jquery Remove Parent Table Row on Button Click Event

By Hardik Savani | September 2, 2019 | | 579 Viewer | Category : jQuery


We will learn how to delete parent table row onclick event in jquery. we will 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 - ItSolutionStuff.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>Hardik Savani</td>

<td>hardik@gmail.com</td>

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

</tr>

<tr>

<td>2</td>

<td>Vimal Kashiyani</td>

<td>vimal@gmail.com</td>

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

</tr>

<tr>

<td>3</td>

<td>Harshad Pathak</td>

<td>harshad@gmail.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 - ItSolutionStuff.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>Hardik Savani</td>

<td>hardik@gmail.com</td>

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

</tr>

<tr>

<td>2</td>

<td>Vimal Kashiyani</td>

<td>vimal@gmail.com</td>

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

</tr>

<tr>

<td>3</td>

<td>Harshad Pathak</td>

<td>harshad@gmail.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>

I hope it can help you...



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.

Tags :

jQuery

We are Recommending you: