IT Certificaions

Google Cloud Platform

Monday, November 14, 2011

Remove table row using JQuery


If you are using JQuery and you have created a table and you want to delete it's row dynamically then you can use following code.


$(document).ready(function() {
    $("#DemoTable tr").click(function() {
            $(this).remove();
        });
});

Here DemoTable is the html Id attribute. So when you will click on the div containing particular row, it will be deleted.
For example if you are using table like..

<table id="DemoTable" >
<tr> 
   <td  width="25%"> </td>
   <td  width="75%"> </td>
</tr>
<tr> 
   <td  width="25%"> </td>
   <td  width="75%"> </td>
</tr>
</table>