HTML:
<div id="parent">
<div class="myDiv"></div>
<div class="myDiv"></div>
<div class="myDiv mySelectedDiv"></div>
<div class="myDiv"></div>
</div>
I append the mySelectedDiv class to the divs, one at a time, dynamically. I want the scrollbar to position at that selected div. Any suggestions?
I've tried the code below to move the scrollbar up and down at the position of the selected div. But its not much accurate when the divs' height change, which they do in my case.
element.scrollBy({
top: 100,
behavior: "smooth"
})