I am trying to scroll into a particular row of a table; the div
along with the table
inside it, both have overflow:auto
. This is my code for scrolling to a particular index of the table:
var table1 = document.getElementById("old_table");
table1.rows[3].scrollIntoView({
behavior: 'smooth',
block: 'center'
});
This is my html:
<div id="old_slab"><table id="old_table" border="2"></table></div>
And my css:
#old_slab{
position: absolute;
top:34em;
left:30em;
width:40em;
height: 15em;
overflow: auto;
}
#old_table{
height: 15em;
overflow: auto;
width: 40em;
}
The rows in my table are dynamically created, hence they are not hardcoded in my html code. Nevertheless, the table isn't empty. For some reason, the scrollIntoView()
isn't working and I don't know why. Please help.
EDIT: Strangely, when I remove the behaviour
and block
arguments, then it works:
table1.rows[3].scrollIntoView(true);