# AJAX effects make browser jump to top of page

**URL:** <https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987>\
**Category:** Rails\
**Created:** [June 20, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987 "2006-06-20T23:56:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [June 20, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987/1 "2006-06-20T23:56:27Z")

</div>

I’ve been having this really annoying issue with any visual effect that  
I use in Rails. Say, for instance, that I have an Element.show or  
Element.hide link to expose a hidden div. Well, the effects work great,  
but if they are located far enough down on the page to necessitate  
scrolling, the effect makes the browser jump to the top of the page.

This is basically the source output that is produced:

switch

 stuff goes here

Anyone run into this, know the cause and know how to stop it?

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [June 21, 2006, 12:23am UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987/2 "2006-06-21T00:23:01Z")

</div>

It’s the href="#" that’s making the page jump like that. You should put  
the onClick on a div or a span (anything but an anchor tag), and have  
some CSS to set a hover: icon change to simulate a link.

Jason

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [June 21, 2006, 2:19am UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987/3 "2006-06-21T02:19:58Z")

</div>

You can also try “Effect.toggle(‘whatever’); return false;” which  
instructs the browser to cancel the navigation.

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [June 21, 2006, 2:32am UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987/4 "2006-06-21T02:32:35Z")

</div>

james payne wrote:

> You can also try “Effect.toggle(‘whatever’); return false;” which  
> instructs the browser to cancel the navigation.

YES! Thank you. I actually just peaked at the 37 signals code and  
noticed they were doing that very thing.

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [June 21, 2006, 2:37am UTC](https://www.ruby-forum.com/t/ajax-effects-make-browser-jump-to-top-of-page/63987/5 "2006-06-21T02:37:22Z")

</div>

Jason R. wrote:

> It’s the href="#" that’s making the page jump like that. You should put  
> the onClick on a div or a span (anything but an anchor tag), and have  
> some CSS to set a hover: icon change to simulate a link.

Thanks for the tip Jason. Yeah, I’ve been avoiding that since I’ve seen  
others get this working (not to mention it negates the whole  
link\_to\_remote method). The “return false;” did the trick.
