How can I add a new row to the specified table using jQuery?

Is there a built-in method for doing this?

And how to make the table rows selectable and then delete the selected row?

+1


source to share


3 answers


$('#yourTableId').append('<tr><td>new row</td></tr>');

      

To remove the selected row, follow these steps:



$('tr').click(function () {
    $(this).remove();
});

      

+10


source


Just did it using this stackoverflow page:

$('.fw').append( 
    $('<tr/>').append( $('<td>').text('foo'))
)

      

Alternative shortcut:



$('.fw').append( $('<tr><td>foo</td></tr>') );

      

Checkout http://docs.jquery.com/Manipulation for more.

+1


source


var row = $('<tr><td>...</td><td>...</td></tr>');
var lastRow = $('table tr:last');
row.insertAfter(lastRow);

      

0


source







All Articles