Reputation: 153
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
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
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
Reputation: 38503
http://plugins.jquery.com/project/ScrollTo
The easiest way is to use this plugin.
Upvotes: 0