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

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.

Read Also:  PHP Laravel Datatable Server Side Processing using jQuery

<!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>Jaydeepgondaliya@gmail.com</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:  Laravel 6 Guzzle PHP HTTP client Request

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.