Restoring page scroll position with jQuery

后端 未结 6 1392
春和景丽
春和景丽 2020-12-05 17:21

I have a page operation that uses something like:

$(\'#thetable tbody\').replaceWith(newtbody);

in an ajax callback. Sometimes, if the user

6条回答
  •  清歌不尽
    2020-12-05 17:38

    Try to use .html() instead of .replaceWith():

    $('#thetable tbody').html( newtbody.html() );.

    I don't know about possible performance bottlenecks here, but it did the trick for me when I was trying to preserve the scroll position of a div, and it seems to do well with the scroll position of the entire page as well.

提交回复
热议问题