Hello
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 ?
Hello
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 ?
http://plugins.jquery.com/project/ScrollTo
The easiest way is to use this plugin.
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.
If you don't want to use a plugin, see element.scrollIntoView
:
$("#test").get(0).scrollIntoView();
// Plain ol' JS:
document.getElementById("test").scrollIntoView();