Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,


How can iset the focus of the current page to the top of page so when click submit button using jquery??
Posted
Comments
Aravindba 28-Jan-14 5:08am    
u cant set focus for top of the page ,can only controls like textbox,buttons,if textxbox on top of page then can set for textbox.

Like Aravindba said, you can't focus on non input items on your page.

However, you make "set view" by scrolling to the top of your page when the user clicks the submit button.

JavaScript
$('form').on('submit', function() {
  $('html, body').animate({scrollTop:0}, 'slow');
});


This way, your page gently eases to the top of your page when the form is submitted.

You can make the code more specific by changing form to the id or name of a particular form like $('#user-form').on(
 
Share this answer
 
You can do like this.
choose a control which is on top of the page and try the below ...
JavaScript
$('#somecontrolontopofpage')[0].scrollIntoView();
 
Share this answer
 
hi,


here is the simplest one:

window.scrollTo(0, 0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900