tags:

views:

411

answers:

3

Is there a built-in method to do this?

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

A: 

Just did it using this stackoverflow page:

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

Alternative shorthand way:

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

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

meder
How to update values of a specified row?
Shore
+3  A: 
$('#yourTableId').append('<tr><td>new row</td></tr>');

To delete clicked row do this:

$('tr').click(function () {
    $(this).remove();
});
RaYell
how to make table rows selectable and then delete a selected row?
Shore
Check my edited answer.
RaYell
I need it to happen when double clicked,is there a dblclick function?
Shore
Yes there is. `$('tr').dblclick(function () { $(this).remove(); });`
RaYell
Finally,is there an attribute of tr that can pop up some hint when user focuses on that row?
Shore
I would use `overlib` library for that: http://www.bosrup.com/web/overlib/
RaYell
What if I want to update the 1st row with new values,instead of append a new row?
Shore
The title attribute can do the hint job:)
Shore
A: 
var row = $('<tr><td>...</td><td>...</td></tr>');
var lastRow = $('table tr:last');
row.insertAfter(lastRow);
John Fisher
What if I want to update the last row with new values,instead of append a new row?
Shore
That is an entirely different question. You can still use "var lastRow = $('table tr:last');" to get the last row, but now you need to find the items that need updating. Something like this might work for you: "var input = lastRow.find('input#someid').val('new value');"
John Fisher