Reputation: 83755
So I have a pre HTML tag with a lot of code in it and with overflow: auto. How can I set the pre tag to be scrolled down (so the last line of the content is visible) with jquery?
Upvotes: 2
Views: 4655
Reputation: 207557
jQuery( function(){
var pre = jQuery("#myPre");
pre.scrollTop( pre.prop("scrollHeight") );
});
Upvotes: 9
Reputation: 69915
Use jQuery
scrollTop
method to set the scroll position of any container. Try this
$("elementSelector").scrollTop(valueToScroll);
Since you want to scroll to the end of the content try this
$("elementSelector").scrollTop($("elementSelector").innerHeight());
Upvotes: 4