I have the following HTML, with scrollbar:
<div id="parent">
<div id="child1">Something</div>
<div id="child2">Something</div>
<div id="child3">Something</div>
<div id="child4">Something</div>
<div id="child5">Something</div>
<div id="child6">Something</div>
<div id="child7">Something</div>
<div id="child8">Something</div>
<div id="child9">Something</div>
</div>
My question is this:
How can I, in pure javascript, position the scroll of the div 'parent' in one of the childs?
I have the following HTML, with scrollbar:
<div id="parent">
<div id="child1">Something</div>
<div id="child2">Something</div>
<div id="child3">Something</div>
<div id="child4">Something</div>
<div id="child5">Something</div>
<div id="child6">Something</div>
<div id="child7">Something</div>
<div id="child8">Something</div>
<div id="child9">Something</div>
</div>
My question is this:
How can I, in pure javascript, position the scroll of the div 'parent' in one of the childs?
Share Improve this question asked Jul 5, 2017 at 16:03 Nuno RibeiroNuno Ribeiro 2,5652 gold badges27 silver badges30 bronze badges1 Answer
Reset to default 10You can use the scrollIntoView
function of JavaScript like this:
document.getElementById('child9').scrollIntoView()
Try it online