How can I prevent the webpage from scrolling back to the top when I use slideup?
Question
I have a webpage with multiple DIV elements. If i use the jquery function SlideUp to hide one (which is towards the bottom of the page), the page automatically scrolls back to the top. How can I prevent this?
To trigger the jquery function, I do something like this:
$(MyLink).click(function() {
MyDiv.slideUp("slow");
}
MyLink
being within MyDiv
which is somewhere in the middle of the page.
Solution 2
What I did was what someone suggested (adding return false
) and it worked:
$(MyLink).click(function() {
MyDiv.slideUp("slow");
return false;
}
OTHER TIPS
How do you trigger the jquery function, via anchors? If so, have the function return false, otherwise the browser will redirect to the href-attribute, which would be '#' in this case.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow