1

So, in chrome and normal browsers

$('.selector').scrollTop(9999999999999999);

will scroll to the bottom, but not in IE.

How do I do this in IE?

dansch
  • 6,059
  • 4
  • 43
  • 59
  • Which version of IE and which version of jQuery use you? – Black Sheep Jan 08 '14 at 22:14
  • This is a duplicate question please see here. http://stackoverflow.com/questions/6736849/scrolltop-not-working-in-ie – Cam Jan 08 '14 at 22:14
  • @Cam That answer has nothing to do with jQuery. Can you explain? – crush Jan 08 '14 at 22:21
  • @crush the answer to fix the issue is there, why does it matter if it is a javascript or jquery? – Cam Jan 08 '14 at 22:47
  • @Cam The accepted answer at that link does exactly what `jQuery.scrollTop(x)` does in `jQuery`'s source. The issue here isn't how to set the scrollTop value. It's that the OP is setting it to an invalid value. – crush Jan 09 '14 at 13:41

1 Answers1

4

The number you are supplying to the function exceeds the max value of a Number in JavaScript.

9999999999999999 //Your number
9007199254740992 //Number.MAX_VALUE in JavaScript

It's probably wrapping to a negative number, or being set to 0.

Try one of these instead:

$('.selector').scrollTop($(document).height());

Or

$('.selector').scrollTop(Number.MAX_VALUE);
crush
  • 16,713
  • 9
  • 59
  • 100
  • Yea.. i didn't use Number.MAX_VALUE because that also broke, I just used 99999999 instead and it worked fine – dansch Jan 09 '14 at 16:45
  • $(document).height() could be wrong, because if they type forever.... and the documnet height is only like 1200, then anything over 1200 will be under the scroll. Basically in the case of scrolling to the bottom, you need the largest number that works – dansch Jan 09 '14 at 16:46
  • `Number.MAX_VALUE` might not be supported by whatever browser you are using. I thought `$(document).height()` isn't the same as `$(screen).height()` and actually is the height of the entire document. – crush Jan 09 '14 at 16:48
  • so you could have a container element (outer most element in document) that is 2000px, your screen height is 900px, but if there is a 800000px overflowed element, is the document 2000px or (800000px + offset) of big element? Either way, my 99999999 number is more than enough – dansch Jan 22 '14 at 21:30
  • the answer is http://jsfiddle.net/c5pJN/1/ you need a big number, document height will only be as big as the outer most element, like body height. If there are big overflowed elements that are cut off, they aren't included – dansch Jan 22 '14 at 21:36
  • That's interesting. I never considered overflowed elements like that. Good to know! – crush Jan 22 '14 at 22:05