I can not programmatically scroll down. When adding a textarea value, the div scrolls, but if I manually scroll this div up, the next time it is added, the scroll won't work as it should. How do I account for custom scrolling?

$(function (){ $('button').click( function(){ $('div').append("<p>" + $(this).prev().val() + "</p>"); $('div').scrollTop($('div').height() + $('div').scrollTop()); }) }); 

http://jsfiddle.net/5DkZc/3/

  • And you can not just take the argument for scrollTop, for example, 10,000? Then everything works. - Oleg Arkhipov
  • this is a crutch. - Deus
  • @eicto, doesn't work for me (chrome). Scroll up and see - the scroll down does not descend - Deus

1 answer 1

The idea of ​​summing up the height of the block and the current position of the scroll is not clear, to scroll to the bottom down you scrollHeigh use scrollHeigh :

 $(function (){ $div=$('div').first(); $('button').click( function(){ $div.append($("<p>").text($(this).prev().val())); $div.scrollTop($div.prop('scrollHeight')); }); }); 
  • I check your example - it doesn't work - Deus
  • just not working? jsfiddle.net/oceog/5DkZc/7 right here - zb '17
  • Uncaught SyntaxError: Unexpected token; - Deus
  • corrected, apparently the wrong one wrote / copied - zb '17
  • one
    This from DOM is not a method but a property - zb '17