Richard Knop
Richard Knop

Reputation: 83755

How to scroll down pre tag

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

Answers (2)

epascarello
epascarello

Reputation: 207557

jQuery( function(){
   var pre = jQuery("#myPre");
    pre.scrollTop( pre.prop("scrollHeight") );
});

jsFiddle Example

Upvotes: 9

ShankarSangoli
ShankarSangoli

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

Related Questions