I tried scrollIntoView
and used .lastchild
but I can't go to the latest comment. Used window.scrollTo
too can't find any solution.
Can anyone have some suggestions on what will work?
const click = () => {
fetch('url')
.then(res => res.json())
.then(data => {
if (data.affectedRows > 0) {
var element = document.getElementById("txt").lastChild;
element.scrollIntoView({behavior: "smooth", block: "end", inline: "center"});
}
})
}
}
{getComment.map(cmnt =>
<div key={cmnt.comment_id} className="article-comments-reply">
<div className="text-box" id="txt">
<h3>{cmnt.username}</h3>
<div className="reply-box">
<h4>{cmnt.comment_text}</h4>
</div>
</div>
</div>
)}