views:

68

answers:

3

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 ?

A: 

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

The easiest way is to use this plugin.

Dustin Laine
anything without using a plugin?
Dario
+1  A: 

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.

R0MANARMY
+2  A: 

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

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

// Plain ol' JS:
document.getElementById("test").scrollIntoView();
Andy E
I'd add a link to MSDN documentation too. http://msdn.microsoft.com/en-us/library/ms536730%28VS.85%29.aspx
R0MANARMY
great! that's what i was looking for.
Dario
@R0MANARMY: Thanks, I usually add a link to either MDC or MSDN. I only add both if there are differences between implementations. In this case, there are no differences so one link should be enough :-)
Andy E