0

I know this has been answered here Scroll to bottom of Div on page load (jQuery), but this solution is not working, when having more than one <div> with different heights.

$('.myContent').scrollTop($('.myContent')[0].scrollHeight);

Is not working with multiple <div> with different heights!

See http://jsfiddle.net/4pfLQ/

Community
  • 1
  • 1
Chris
  • 4,255
  • 7
  • 42
  • 83

3 Answers3

3

Try this:

$('.myContent').each(function () {
    $(this).scrollTop($(this)[0].scrollHeight);
});

FIDDLE DEMO

palaѕн
  • 72,112
  • 17
  • 116
  • 136
0

With this code - $('.myContent').scrollTop($('.myContent')[0].scrollHeight); you are only targeting the first div of DOM tree having class myContent due to the inclusion of [0] in the code.

swapnesh
  • 26,318
  • 22
  • 94
  • 126
0

You have to decide, which of DIVs you want to scroll. You can select one of them

$(".myContent:eq(N)")

where N - is a number of the DIV, counts from 0. Or if you want to scroll every DIV, then try it:

$('.myContent').each(function () {
    $(this).scrollTop($(this)[0].scrollHeight);
});
lorado
  • 336
  • 1
  • 7