I have a requirement where I am updating the innerHTML of DOM Element inside window.onload and then I want to scroll to one element inside that innerHTML based on hash value in address bar.
The issue here is that innerHTML may contain images etc.
Sample Code:
window.onload = function() {
document.getElementById('container').innerHTML = '<div><img src="image1.png"/><div id="scrollToElement">Scroll Here</div><img src="image2.png"/><img src="image3.png"/></div>';
document.getElementById('scrollToElement').scrollIntoView();
}
This scrolls to some random position.