So I'm migrating a webpage from a basic structure to WordPress and one of the pages has a table of contents. The ToC has plus signs that allow you to expand different areas of the ToC and when you click on links and what not, the body scrolls properly, however, the actual HTML tag of the entire page is not scrolling up.
So basically, this is a very rough mock up of what the page is laid out like
<html overflow-y: scroll; margin-left/right: auto; width: 1235px;>
<body overflow-y: scroll>
...primary content here centered by html css
</body>
</html>
So basically, clicking the plus signs properly uses href tags to set the BODY scroll window, however, since the html document isn't scrolling as well, it doesn't properly align the page to the header of the section you just clicked to navigate to. Here is the code for the openClose function utilized by the plus signs:
function openClose(theName, menuArray, theID) {
for(var i=0; i < menuArray.length; i++) {
if (menuArray[i] == theID) {
if (document.getElementById(theID).style.display == "block") {
document.getElementById(theID).style.display = "none";
document.getElementById("tick_"+menuArray[i]).innerHTML = "+";
eraseCookie(theName); }
else {
document.getElementById(theID).style.display = "block";
document.getElementById("tick_"+menuArray[i]).innerHTML = "-";
newCookie(theName,menuArray[i],exp); }
}
else {
document.getElementById(menuArray[i]).style.display = "none";
document.getElementById("tick_"+menuArray[i]).innerHTML = "+"; }
}
$(window).scrollTop(0); // this is just one of many examples
}
The scrollTop
is just one of the many examples I've tried, to get the HTML document to scroll to the top, however, nothing just seems to do anything. I'm not trying to scroll the body, I want to scroll the master vertical scroll bar. I figured that in the openClose on click function that I would put such a function at the end so that it scrolls the entire document back up after it navigates to the position defined by the on click event. But again, nothing happens. Am I missing something simple?
I googled and found this other page Scroll to the top of the page using JavaScript/jQuery? but none of the examples work.