Within a div element, I have an abundance of content:
<div id="x" class="unhidden">
text and additional divs
</div>
The CSS class 'unhidden' is defined as:
display: block;
Upon clicking a link, the element with the id='x' changes to class='hidden' through javascript. The 'hidden' class includes:
display: none;
Subsequently, the div element becomes hidden. Everything seems to be working fine so far. Now, my objective is to revert and reveal the full div='x'
, while also scrolling down to a specific section within the id='x'
div.
Hence, when the back button is clicked, first, the class reverts back to unhidden
using javascript. Then, within the same function, this script is executed:
window.scroll(0, findPos(document.getElementById(GoTo)));
'GoTo' represents the ID of the particular div that needs to be scrolled to. Utilizing this function for scrolling:
function findPos(obj) {
var curtop = 0;
if (obj.offsetParent) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}
The scripting correctly determines the position to navigate to, but it fails to execute the scroll.
The scrolling process works smoothly when isolated from the hiding/showing functionality. However, in this scenario, there appears to be a blockage caused by the toggle between hidden and unhidden states.
Do you have any potential solutions or insights to offer?