Reputation: 17
My Html code is
<p id="4" style="color: red;">Dit antwoord is verplicht</p>
<p id="5" style="color: red;">Dit antwoord is verplicht</p>
i have add scrollIntoView but it's not working any other solution for scroll to particular id in react js
document.getElementById(4).scrollIntoView();
Upvotes: 0
Views: 1476
Reputation: 446
Here you can give try,
window.scrollTo(0,this.findPosition(document.getElementById(4)));
Below function is for finding place of particular id.
findPosition(obj) {
var currenttop = 0;
if (obj.offsetParent) {
do {
currenttop += obj.offsetTop;
} while ((obj = obj.offsetParent));
return [currenttop];
}
}
Upvotes: 1