Gabriel Slomka
Gabriel Slomka

Reputation: 1527

JS Focus Scrollable Div

I have a button that opens up a scrollable div.

If i use the arrow keys on the keyboard, it wont scroll the div.

However, if i click on the div (anywhere) i can scroll using arrow keys.

How can i make the div automatically focused ? I have tryed using raw .focus(), ive tryed using jquery as well: $(elm).focus() and $(elm).click() both wont work. Any ideas how to achieve this ?

The element selector is correct, im selecting the div that contains the scrollbar.

Upvotes: 2

Views: 1270

Answers (1)

Gabriel Slomka
Gabriel Slomka

Reputation: 1527

In order to focus a element, you need a TabIndex. Adding a tabIndex then calling .focus() solves the problem.

Upvotes: 0

Related Questions