Tanu
Tanu

Reputation: 71

window.scrollTo is not working in Internet Explorer 11

I want the scrollbar to be positioned on top by default as soon as I launch the page.But the below code works fine in chrome but not in IE11.

If I try to debug the script, the scrollbar is positioned on top.

$(document).ready(function () {
  window.scrollTo(0,0);
 }

I tried different solution online such as

$(window).scroll().scrollTop(0);
document.body.scrollTop(0);

But nothing worked in IE.Kindly help me

Upvotes: 5

Views: 9619

Answers (2)

Rani Moreles Rubillos
Rani Moreles Rubillos

Reputation: 1108

Try using

$('body,html').scroll().scrollTop(0);

or

$('body,html').animate({scrollTop:0});

Upvotes: 3

vidit chauhan
vidit chauhan

Reputation: 41

Though this is a very old question, but updating here for someone looking for a solution.

Try using:

element.scrollTop = 0;

This should work on all browsers.

Upvotes: 4

Related Questions