Monthly Archives: December 2011

Jquery to scroll down or up OnClick of an anchor tag

Recently i was working on an MVC master detail grid UI. There is a master grid which shows link to detail grid. When you click on the link of any row, a detail grid appears below the master grid. So the issue was detail grid did not have focus onclick of master link. which was very much desired by the user.

Here is a the small piece of jquery code which solved the problem. It not only scrolls down but also provides a decent animation effect while sliding down/up.

$(function () {
$(".productsLink").live('click', function () {
$('html,body').animate({scrollTop: $("#products").offset().top }, "slow");

Where products is the id of detail div.

Hope it helps!