JQuery Remove Parent Table Row on Button Click Event
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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Moment Get Current Date Example
- How to Print Iframe Content using Jquery?
- JQuery Get Days Difference Between Two Dates Example
- JQuery Toggle Hide Show Div on Click Event Example
- How to Get Selected Radio Button Value in JQuery?
- JQuery Redirect to Another Page After 5 Seconds Example
- How to Get Last Element from Array using JQuery?
- How to Remove Empty or Null Values from JSON using JQuery?
- How to Disable F5 Refresh Button using JQuery?
- Add Edit Delete Table Row Example using JQuery
- JQuery Disable Right Click, Cut, Copy and Paste Example
- JQuery - How to Push Specific Key and Value in Array?
- How to Remove Comma from String in JQuery?
- JQuery Datepicker Example using JQuery UI JS