views:

126

answers:

3

When the user clicks a button, I want his browser to automatically scroll to an <a> with a certain href (let's call it "abc"). Ideally the scrolling would be nicely animated in some way.

+4  A: 

Give a look to the jQuery.scrollTo plugin.

With that plugin you could simply:

$.scrollTo('a[href=abc]');
CMS
+2  A: 

You don't need any plugin.

$(document.documentElement).animate({
    scrollTop: $('a#abc').offset().top
});
J-P
A: 

Way simpler:

element_to_scroll_to = document.getElementById('anchorName2');
element_to_scroll_to.scrollIntoView();

Even no need for jQuery ;)

Mandx