# Scroll to anchor from RJS

**URL:** <https://www.ruby-forum.com/t/scroll-to-anchor-from-rjs/116251>\
**Category:** Rails\
**Created:** [October 3, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/scroll-to-anchor-from-rjs/116251 "2007-10-03T21:44:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [October 3, 2007, 9:44pm UTC](https://www.ruby-forum.com/t/scroll-to-anchor-from-rjs/116251/1 "2007-10-03T21:44:30Z")

</div>

Is there an way to tell the browser to scroll to a certain anchor from  
an RJS template?

I’m doing a page update, adding stuff at the bottom and want to  
browser to go there after it’s been added.

Thanks,  
Helzer

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [October 3, 2007, 9:55pm UTC](https://www.ruby-forum.com/t/scroll-to-anchor-from-rjs/116251/2 "2007-10-03T21:55:38Z")

</div>

On 10/3/07, helzer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there an way to tell the browser to scroll to a certain anchor from  
> an RJS template?
> 
> I’m doing a page update, adding stuff at the bottom and want to  
> browser to go there after it’s been added.

Something like this should work (untested):

render :update do |page|  
…  
page[‘myanchor’].scrollTo  
end

Which should generate the javascript:

$(‘myanchor’).scrollTo();

HTH

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [October 3, 2007, 10:25pm UTC](https://www.ruby-forum.com/t/scroll-to-anchor-from-rjs/116251/3 "2007-10-03T22:25:00Z")

</div>

Hi Bob,

It turns out that the effects library is my friend:  
page[@dest\_id].visual\_effect :scroll\_to

Thanks,  
Amir
