Keep page position when update an DOM element using jQuery
I have a long table with many rows and have to scroll down to see all of them. When I update the last row, the browser automatically scroll to the top of the page. How can I fix it开发者_JAVA百科?
<table>
.....
<tr>
<td id='row_xxx'>
</td>
</tr>
.....
</table>
and script
$("row_xxx").html("abc abc ab");
I'll guess you could use the window.scrollto() functionality.
http://www.w3schools.com/jsref/met_win_scrollto.asp
Or jquery scrolltop
$("#row_xxx").scrollTop($("#row_xxx").attr("scrollHeight"));
You can use scrillHeight attribute.
$("#myTable").attr(
{
scrollTop: $("#myTable").attr("scrollHeight")
});
精彩评论