Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving to named anchor after jquery/javascript processing

How do move focus to a different section (named anchor) on the same page after doing some jquery processing.

Function ABC() does some processing and afterwards, I need to move the user to a section on the same page (further down the page).

like image 406
robasta Avatar asked May 11 '11 13:05

robasta


2 Answers

You can use the code below to scroll the screen to a <div id="navigation">. Just change the selector to match the element you want to scroll to.

$('html, body').animate({ scrollTop: $('#navigation').offset().top }, 'slow');
like image 191
derek Avatar answered Sep 29 '22 21:09

derek


location.href=location.href.replace(/#.+/,'')++'#namedanchor' or

document.getElementById('#namedanchor').scrollIntoView(true)

The first appends the hash to the address URL

like image 40
kennebec Avatar answered Sep 29 '22 21:09

kennebec