I am using this JS to show/hide DIV's on the page to stop the page becoming too busy. The problem is that the header links are half way down the page, and so the user will most likely be scrolled somewhat down the page. Then clicking the links causes the browser to scroll back to the top again. Is there a way to stop this?
Just a bonus thing would be to have the div that is displayed so something like scroll nicely or fade in, but that isn't as important. Thanks!!
HTML LINK:
<a href="#" onclick="toggle_visibility('content1');">Charity Partnership</a>
<div id="content1" class="alist" style="display:none;">Content</div>
JS:
function toggle_visibility(id) {
var thelist = document.getElementsByClassName("alist");
for (var i = 0; i < thelist.length; i++) {
thelist[i].style.display = 'none';
}
var e = document.getElementById(id);
if (e.style.display == 'block') {
e.style.display = 'none';
} else {
e.style.display = 'block';
}
}