ItSolutionStuff.com

JQuery Remove Parent Table Row on Button Click Event

By Hardik Savani • July 7, 2023
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...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Moment Get Current Date Example

Read Now →

How to Print Iframe Content using Jquery?

Read Now →

JQuery Get Days Difference Between Two Dates Example

Read Now →

JQuery Toggle Hide Show Div on Click Event Example

Read Now →

How to Get Selected Radio Button Value in JQuery?

Read Now →

JQuery Redirect to Another Page After 5 Seconds Example

Read Now →

How to Get Last Element from Array using JQuery?

Read Now →

How to Remove Empty or Null Values from JSON using JQuery?

Read Now →

How to Disable F5 Refresh Button using JQuery?

Read Now →

Add Edit Delete Table Row Example using JQuery

Read Now →

JQuery Disable Right Click, Cut, Copy and Paste Example

Read Now →

JQuery - How to Push Specific Key and Value in Array?

Read Now →

How to Remove Comma from String in JQuery?

Read Now →

JQuery Datepicker Example using JQuery UI JS

Read Now →