1.how to highlight the row when mouse is on,then de-highlight when mouse is out
2.how to update a specified row with new values?
3.how to get number of rows in table?
EDIT: the one with best answer for q2 will be marked as answer for this post:)
1.how to highlight the row when mouse is on,then de-highlight when mouse is out
2.how to update a specified row with new values?
3.how to get number of rows in table?
EDIT: the one with best answer for q2 will be marked as answer for this post:)
1. http://docs.jquery.com/Events/mouseover
I believe you can use this or .hover.
$('tr').mouseover(function() {
$(this).addClass('over');
}).mouseout(function() {
$(this).removeClass('over');
});
And add a over class in your CSS.
2. You don't update a row, you update the table cells inside the row.
$('tr:first td:first').text( 'something' )
3.
alert( $('table tr').length ); // count all descendant table rows
$('#mytable').find('tr').hover(function() {
$(this).addClass('active');
}, function() {
$(this).removeClass('active');
});
Along with this CSS:
#mytable tr.active td {
background-color: #ccc;
}
You said update a "row" but all you can really update is cells, unless you want to create whole new cells.
$(cell).html('Contents');
Or:
var $cell = $('<td>').html('Contents');
$(row).html($cell);
Or if a table row has 3 cells, to update the first one:
$(row).find('td').eq(0).html('Contents');
$('#mytable').find('tr').length;
For the first question:
$("#table1 tr").hover(
function()
{
$(this).addClass("highlight");
},
function()
{
$(this).removeClass("highlight");
}
For the third question:
var count = $("table1 tr").length