How do I set focus to the top of a page?
Solution 1$('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.
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
You can make it focusable by adding a tabindex=0 attribute value to it. That will add the element to the list of elements that can be focused by pressing the Tab key, in the sequence of such elements as defined in the HTML document.
I found this use of the window.scrollTo function:
window.scrollTo(0,0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With