admin管理员组文章数量:1403081
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
本文标签: javascriptselect the second row from the html table using jqueryStack Overflow
版权声明:本文标题:javascript - select the second row from the html table using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744368908a2602923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论