Yes - this is possible. In order to do it, you need to assign a tabindex...
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.
The focus() is an inbuilt method in jQuery which is used to focus on an element. The element get focused by the mouse click or by the tab-navigating button. Here selector is the selected element. Parameter: It accepts an optional parameter “function” which specifies the function to run when the focus event occurs.
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.
To make a div focusable, it needs to have a tabindex
attribute.
<div id='test' tabindex='1'></div>
Then, you can focus with e.g.
$('#something').click(function() {
$('#test').focus();
});
Use $(window).scrollTop()
It'll scroll the window to the particular item.
Here is the example
var scrollPos = $(".focusme").offset().top;
$(window).scrollTop(scrollPos);
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