JQuery - Remove Parent Table Row on Button Click Event Example
When “JQuery - Remove Parent Table Row on Button Click Event Example” moves through design, development and browser testing, the complete guide can clarify hand-offs and time spent on revisions while leaving code quality, accessibility and released behaviour as the real measures of success.
For API changes, browser support and current usage patterns, compare the snippet with the official jQuery website before adopting it in production.
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>[email protected]</td>
<td><button class="btn-remove">Remove</button></td>
</tr>
<tr>
<td>2</td>
<td>Demo</td>
<td>[email protected]</td>
<td><button class="btn-remove">Remove</button></td>
</tr>
<tr>
<td>3</td>
<td>Test Demo</td>
<td>[email protected]</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>[email protected]</td>
<td><button class="btn-remove">Remove</button></td>
</tr>
<tr>
<td>2</td>
<td>Demo</td>
<td>[email protected]</td>
<td><button class="btn-remove">Remove</button></td>
</tr>
<tr>
<td>3</td>
<td>Test Demo</td>
<td>[email protected]</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....
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get Current Page URL, Path, Host and hash using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- JQuery Remove All Unwanted Whitespace From String Example
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example