Jquery

Jquery Remove Parent Table Row on Button Click Event

Pinterest LinkedIn Tumblr
<!DOCTYPE html>
<html>
<head>
    <title>Jquery Remove Parent Table Row on Button Click Event: Real Programmer</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>Siddharth</td>
        <td>siddharth@gmail.com</td>
        <td><button class="btn-remove">Remove</button></td>
    </tr>
    <tr>
        <td>2</td>
        <td>Yash</td>
        <td>yash@gmail.com</td>
        <td><button class="btn-remove">Remove</button></td>
    </tr>
    <tr>
        <td>3</td>
        <td>Chotu</td>
        <td>chotu@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>

Write A Comment