0

I am working on a website where I need to scroll the user to the top of the page (with jQuery) after form submit, everything works except for the actual scrolling, I believe the reasoning for this is that the person before wrote the entire page in <tables> and the table element is scrolling, not the body. So standard soutions like:

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

are not working, as they do not scroll the table/form to its starting point. Does anyone have a solution to this(other than tweaking the table not scroll on overflow)?

Typhomism
  • 284
  • 1
  • 3
  • 13
  • Does this apply? http://stackoverflow.com/questions/1144805/how-do-i-scroll-to-the-top-of-the-page-with-jquery – vpzomtrrfrt Nov 06 '14 at 16:56
  • @vpzomtrrfrt ive tried that, i dont need to scroll to the top of a page per say, i need to scroll a tables whos overflow was handled as scroll to the top (its original starting position) – Typhomism Nov 06 '14 at 16:58
  • Try this: `$('*').animate({ scrollTop: 0 }, 800);` - This will scroll whatever is there to scroll :) – LcSalazar Nov 06 '14 at 16:59
  • @LcSalazar man, that's so dirty. But it worked! Put that as an answer so I can accept it? – Typhomism Nov 06 '14 at 17:20
  • that's ultra-dirty, you should invest some minutes in finding out the only element that has scrolled, instead of setting up hundreds of animations. – rupps Nov 06 '14 at 17:59

1 Answers1

0

You may try to target every element with the selector *, and then apply the animation to those:

$('*').animate({ scrollTop: 0 }, 800);
LcSalazar
  • 16,524
  • 3
  • 37
  • 69