HDTuto.com

Jquery Delete Table Row on Click Event Example



I am going to show you example of jquery remove table row onclick. We will look at example of jquery remove parent tr example. i would like to share with you jquery click remove parent tr. we will help you to give example of jquery delete table row onclick.

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 - HDTuto.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 - HDTuto.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...




May 2, 2020 | Category : JQuery



Blog Search