I have a small problem with a webpage returning back to the top of the page after a javascript function is executed.
Basically, I have a small javascript function that toggles the visibility of a div by changing it's display style. the code is the following:
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
I then call this with a link that looks like this:
<a href="#" onclick="toggle_visibility('001');" class="expand">[+/-] Hide/Show Info</a>
and the div looks something like this:
<div id="001" style="display:none;">
hello world
</div>
This works just fine. But when I click on my "expand/hide" link to toggle the visibility of the div, the page always returns to the top, so I have to scroll back down to the bottom every time.
I have tried adding the the following changes at the end of my javascript function, but neither of them works:
window.location = 'test.php#' + id; //where test.php is my current page
and
window.location.hash=id;
Any help would be appreciated in fixing this issue Thanks.