Jan 29, 2015

Remove row like tr from table using jQuery

jQuery provide a method remove() using this we can remove rows of the table, sometimes we need to remove row from the table here we can use this thing. Suppose we are appending searched item to a table, it will be good in first time if we click again for other search then we need to clear appended item from the table and then add again, in this scenario we will use below functions.

$('#remove').click(function () {
            $('#SearchTextID tr).remove();
        })
Here SearchTextID is a <table> id
Like
<table>
    <tr>
        <td>your text</td>
    </tr>
    <tr>
        <td>your text v2</td>
    </tr>

</table>
Above jQuery will help you to remove all <tr> tag from <table>
If you want to remove last or first row of the table see below:
Remove last row
$('#remove').click(function () {
            $('#SearchTextID tr:last).remove();
        })
Or to remove first row
$('#remove').click(function () {
            $('#SearchTextID tr:first).remove();
        })