I use the following jquery function for highlight the row ( using bg color ) in Html table.It was working fine.my question is how to select the second row from the table.'highlight' is a class
.highlight td {
background: #E7EFFA;
}
$('#Tabnameabcd tr').mouseover(function() {
if ($.trim($(this).text()) != '')
$(this).addClass('highlight');
}).mouseout(function() {
$(this).removeClass('highlight');
});
which means:
name age depart
test 12 test
test1 13 tested
here name,age,depart as a first row.that is title. next test,test1 are elements of the tabe.if i use that jquery function the title( name,age,depart ) are apply.i need to apply that jquery function only to the elements of the table not a title?how to do this?
I use the following jquery function for highlight the row ( using bg color ) in Html table.It was working fine.my question is how to select the second row from the table.'highlight' is a class
.highlight td {
background: #E7EFFA;
}
$('#Tabnameabcd tr').mouseover(function() {
if ($.trim($(this).text()) != '')
$(this).addClass('highlight');
}).mouseout(function() {
$(this).removeClass('highlight');
});
which means:
name age depart
test 12 test
test1 13 tested
here name,age,depart as a first row.that is title. next test,test1 are elements of the tabe.if i use that jquery function the title( name,age,depart ) are apply.i need to apply that jquery function only to the elements of the table not a title?how to do this?
Share Improve this question edited Sep 19, 2012 at 11:25 Danil Speransky 30.5k6 gold badges69 silver badges78 bronze badges asked Sep 19, 2012 at 4:34 UserUser 1,66210 gold badges41 silver badges67 bronze badges 1-
Put the header rows in a thead element, put the id on a tbody element. Instead of a listener on every single row, consider a single listener on the tbody that uses
event.target
to get the row, then goes from there. – RobG Commented Sep 19, 2012 at 5:20
2 Answers
Reset to default 4To get second row: $('#Tabnameabcd tr').eq(1)
or $('#Tabnameabcd tr:eq(1)')
.
To get all rows from second one (Demo: http://jsfiddle/pXj5F/):
$('#Tabnameabcd :nth-child(n+2)')
Also you should think about thead
and tbody
...
Try like this
$('#mytable_id tr').eq(1).(your function here);
and you want to apply for the rows not the tiltes then you can also use
$("#mytable_id td").function({
//Play here
});
it will applicable to all the td's of your table excluding titles.you can also use ".not()" function instaed of this
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744368908a4570849.html
评论列表(0条)