Dario
Dario

Reputation: 153

Scroll to a div contained in a overflow:auto

i have this:

<div id="parent" style="overflow:auto">
   ...
   <div id="test">Hello</div>
   ...
</div>

My question is: how to scroll parent div to have test div as first line of parent ?

Upvotes: 1

Views: 492

Answers (3)

Andy E
Andy E

Reputation: 344517

If you don't want to use a plugin, see element.scrollIntoView:

$("#test").get(0).scrollIntoView();

// Plain ol' JS:
document.getElementById("test").scrollIntoView();

Upvotes: 2

Roman
Roman

Reputation: 20246

If you're using jQuery (or are able to do so), take a look at the ScrollTo plugin.

From documentation

With this plugin, you will easily scroll overflowed elements, and the screen itself. It gives you access to many different options to customize and various ways to specify where to scroll.

Upvotes: 1

Dustin Laine
Dustin Laine

Reputation: 38503

http://plugins.jquery.com/project/ScrollTo

The easiest way is to use this plugin.

Upvotes: 0

Related Questions