Home » Remove HTML Table Row and Column using jQuery

Remove HTML Table Row and Column using jQuery

Today, We want to share with you Remove HTML Table Row and Column using jQuery.In this post we will show you Remove table column and Row using jQuery, hear for How to add, edit and delete rows of a HTML table with jQuery we will give you demo and example for implement.In this post, we will learn about with an example.

Remove HTML Table Row and Column using jQuery

There are the Following The simple About Remove HTML Table Row and Column using jQuery Full Information With Example and source code.

As I will cover this Post with live Working example to develop jQuery remove HTML table column and Row Example, so the some major files and Directory structures for this example is following below.

  • index.html
Read Also:  Laravel Dynamic Change page Title Tags

How to add or remove rows inside a table dynamically using jQuery

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add and delete table row using jQuery</title>
<style type="text/css">
    form{
        margin: 15px 0;
    }
    form input, button{
        padding: 3px;
    }
    table{
        width: 100%;
        margin-bottom: 15px;
		border-collapse: collapse;
    }
    table, th, td{
        border: 1px solid #3d3d3d;
    }
    table th, table td{
        padding: 10px;
        text-align: left;
    }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $(".add-row").click(function(){
            var name = $("#name").val();
            var email = $("#email").val();
            var results = "<tr><td><input type='checkbox' name='liveRow'></td><td>" + name + "</td><td>" + email + "</td></tr>";
            $("table tbody").append(results);
        });
        
        $(".remove-row").click(function(){
            $("table tbody").find('input[name="liveRow"]').each(function(){
            	if($(this).is(":checked")){
                    $(this).parents("tr").remove();
                }
            });
        });
    });    
</script>
</head>
<body>
<h3>Add and delete table row using jQuery Example</h3>
    <form>
        <input type="text" id="name" placeholder="User Name">
        <input type="text" id="email" placeholder="Email Address">
    	<input type="button" class="add-row" value="Add Row">
    </form>
    <table>
        <thead>
            <tr>
                <th>Select User</th>
                <th>User Name</th>
                <th>User Email</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox" name="liveRow"></td>
                <td>Jaydeep Gondaliya</td>
                <td>[email protected]</td>
            </tr>
        </tbody>
    </table>
    <button type="button" class="remove-row">Remove Row</button>
</body> 
</html>                            

Remove table Row using jQuery

core Logic of the jQuery Remove Row source code

$(document).on('click', 'button.removebutton', function () { // <-- changes
     alert("testing Mode..");
     $(this).closest('tr').remove();
     return false;
 });

Demo Remove table Row using jQuery

Remove table column using jQuery

core Logic of the jQuery Remove Column source code

$('table').delegate('td,th', 'click', function() {
    var liveidx = this.cellIndex;
    $(this).closest('table').find('tr').each(function() {
        this.removeChild(this.cells[ liveidx ]);
    });
});

Demo Remove table column using jQuery
Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Angular 2 interview questions Answers

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Remove a specific table row and Column using jQuery.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 6 Where null and Where not null eloquent query
  2. Read Also:  Add Edit Delete Table Row Example using JQuery
  3. Read Also:  VUE js get current array index position
  4. Read Also:  What is jquery Hasclass? - jQuery Check if Element has Class
  5. Read Also:  Installing laravel on windows wamp xampp
  6. Read Also:  Upload Multiple Images Preview using PHP
  7. Read Also:  PHP Add JSON object Data Example
  8. Read Also:  jQuery multiple carousel image slider
  9. Read Also:  Installing laravel on windows wamp xampp
  10. Read Also:  PHP Add JSON object Data Example

Leave a Comment

Your email address will not be published. Required fields are marked *