set Focus on Top of screen jquery


I have a page with multiple tabs and i Show and hide them based on a href click using jquery. Whenever I click on "a href", the page is scrolled down. Am trying to set the focus on the top of the page. This is my first project in Jquery. I tried the following but still doesnt work.

<ol><li>scroll(0, 0);</li> <li>window.scrollTo(0,0);</li> <li>window.scrollTo(0, document.body.scrollHeight);</li> <li>var ctrl = document.getElementById('lnkCreateJob'); ctrl.focus();</li> </ol>

please do share some light on that matter.


Try like this:

$(".gototop").click(function(){ var focusElement = $("#contents"); $(focusElement).focus(); ScrollToTop(focusElement); }); function ScrollToTop(el) { $('html, body').animate({ scrollTop: $(el).offset().top - 50 }, 'slow'); } <h2><a href="http://jsfiddle.net/akhurshid/zhPtw/" rel="nofollow">SEE DEMO</a></h2>


Just use <a href="#">Your link</a>. It will take you to the top of the page.


you have to create a element (any html element ex div) with id="#" in the top of the page. you have to put this # in the href of the 'a' link. Then, your method should be in onclick method of the 'a' link.


  • Infinite Scroll Effect with javascript
  • Scroll Down [GeckoFx + Javascript]
  • Selenium python unable to scroll down
  • jQueryUI sortable and draggable target won't scroll horizontally for drop but will for sort
  • wrong item changes in recyclerview
  • How to expand parent div to account for child's overflow?
  • Two column unique constraint ActiveAndroid
  • How to format code on aptana 3?
  • PHPStorm Namespace support not working for Symfony2 projects
  • cd command not working with execvp
  • Making Google Visualization - Annotation Chart to work in GWT
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • C# List of Panels
  • Find JSON nested nodes using multiple string values
  • Does Apportable support to build library binary (.a/.so)?
  • Update Google Maps traffic layer without page reloading
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Chart.js Multiple dataset
  • How to know when stdin is empty if it contains EOF?
  • Switching to Release Build causes runtime error in Web Reference
  • Alert pop up with LWUIT
  • Java: can you cast Class into a specific interface?
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • Align navbar back button on right side
  • Change an a tag attribute in JavaScript based on screen width
  • jQuery tmpl and DataLink beta
  • QuartzCore.framework for Mono Develop
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • How to disable jQuery.jplayer autoplay?
  • How to delete a row from a dynamic generate table using jquery?
  • AngularJs get employee from factory
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • using HTMLImports.whenReady not working in chrome
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • How to load view controller without button in storyboard?