The following won\'t work unless I remove height: 100%
from body and html. However, i need that style as I am using it for other elements on the page.
<
I had the same problem with body { height: 100%; }
and scrollTop(0)
.
Since I was not able to change html/css for different reasons,
workaround was to remove height
before scrollTop
, and then revert to initial state.
// Change height:100% into auto
$('body').css('height', 'auto');
// Successfully scroll back to top
$('body').scrollTop(0);
// Remove javascript added styles
$('body').css('height', '');