Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent the webpage from scrolling back to the top when I use slideup?

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.

like image 507
Anthony Avatar asked Dec 07 '25 12:12

Anthony


2 Answers

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.

like image 83
Ickmund Avatar answered Dec 10 '25 00:12

Ickmund


What I did was what someone suggested (adding return false) and it worked:

$(MyLink).click(function() {
MyDiv.slideUp("slow");
return false;
}
like image 45
Anthony Avatar answered Dec 10 '25 01:12

Anthony