Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change focus into particular div

Tags:

jquery

People also ask

Can you set focus to a div?

Yes - this is possible. In order to do it, you need to assign a tabindex...

How do you set focus on a specific element in HTML?

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.

Can we focus on a div jQuery?

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.

How do I make a div keyboard focusable?

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);