I have a tabl开发者_StackOverflow社区e with id as "mytable" and have lots of rows in it...
I want to select a row with id ="row_100" in it using jquery..
how to do this..
code
function highlight_tran(tranid)
{
var rowpos = $('#'+tranid).position();
$('#trtable').scrollTop(rowpos.top);
}
where trtable is the container id of the table
tranid is id of the tr, here tranid is the one user wants to see...so it may not be seen as this is scrollable table, to make it view i am doing this function, for autoscrolling...
now its working to the last row, but after that when we select any top rows autoscroll will not move above to the exact TR position althoughh the "tranid" passed is correct...I am messed up with this... is there any another neat solution to achieve this....
Why not just use the JQuery selector?
$("#row_100");
If you are selecting a certain row in different tables, maybe you should consider assigning id
for your tables, and class
to the row:
<table id="first_part">
...
<tr class="special">...</tr>
...
</table>
<table id="second_part">
...
<tr class="special">...</tr>
</table>
And then select using something like $("#first_part .special")
.
if you have multiple tables with mass amount of rows you can use jquery Descendant Selector by doing something like:
Table
<table id="table_1">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<!-- .... -->
<tr><td>102</td></tr>
<tr><td>103</td></tr>
</table>
jQuery
$("#table_1 tr:eq(100)").css(/*...*/);
or if your rows have an ID and-or your using live element insertions,
$("#table_1 tr#row_100").css(/*...*/);
You can just use a #id selector here (which is the fastest way as well), like this:
$("#row_100");
Just for the sake of completeness, if row_100 means the 100th row, you can also do this
$("tr:eq(99)")
- which would select the 100th instance of tr if you've got more than one table, us the table's id before the tr:
$("#myTable tr:eq(99)")
EDIT
Okay so I've tested this and it at least selects the correct row given
var selector = "#trtable tr:eq(" + tranid + ")";
$(selector).scrolltop(this.top);
精彩评论