1

Is there a jQuery technique to select all the page controls/divs with a non-zero scrollbar position?

I'm trying to solve a problem faced by many; essentially after a partial asp.net postback all the controls/divs that had a scrollbar with a non-zero value (ie: were scrolled down to some position) are reset to the zero (top of the scrollbar).

My approach is to have a jQuery script save all the scrollbar positions for all the controls/divs contained on a page and after the postback, restore all the scroll bar positions.

Is it possible, can it even work? If it is, how do I use jQuery to select all the divs with scrollbars and then save those positions.

Thanks!

Matt
  • 25,943
  • 66
  • 198
  • 303

1 Answers1

1

As far as I know, there is no way to select elements by whether or not they have a scrollbar. If I were to do this, I think my approach would be to target elements that could have scrollbars, then test to see if the scrollTop = 0. For example:

$('div, select[size]').each(function() {
     //test for non-zero scrollTop
     if ($(this).scrollTop() != 0) {
         //save the element by id and the scrollTop value
         //maybe use a cookie, or a string that can be passed
         //between server and client
     }
});
Ender
  • 14,995
  • 8
  • 36
  • 51