1

I'm having an issue getting some simple code working for both Chrome and IE11 working properly.

Simply:

This works in IEii but not chrome:

var s = $('html, body').scrollTop();
    alert (s);

And this works in chrome but not IE:

var s = $('body').scrollTop();
alert (s);

Any help to get it working properly for both browsers?

Thanks,

spas2k
  • 499
  • 1
  • 6
  • 15
  • scrollTop() getter returns only first matched element in set top value and chrome scrollingElement is the body, not html. That's why `$('html, body').scrollTop()` doesn't work on chrome. – A. Wolff Feb 16 '16 at 16:09
  • Possible duplicate of [How to detect scroll position of page using jQuery](http://stackoverflow.com/questions/17441065/how-to-detect-scroll-position-of-page-using-jquery) – JJJ Feb 17 '16 at 12:33

2 Answers2

3

How about you use window instead of body

$(window).scrollTop();
epascarello
  • 204,599
  • 20
  • 195
  • 236
-3

Please try below code..

var get_scroll = jQuery(window).scrollTop();

console.log(get_scroll);

Gunjan
  • 1
  • 3