cerberos
cerberos

Reputation: 8035

$.focus() not working in chrome

In chrome's developer tools console I'm selecting an input[type="text"] element, then trying to focus on it eg $('input#foo').focus(). It doesn't work, no error is thrown but the element isn't focused.

I spent half an hour trying to figure out the problem so am posting this in order to help others who have this 'problem' since I didn't find an answer on SO.

Upvotes: 4

Views: 5576

Answers (2)

chenyu wang
chenyu wang

Reputation: 1

try setTimeout instead. you probably should focus the page after you enter the code

setTimeout(() => temp1.focus(), 3000);

Upvotes: 0

cerberos
cerberos

Reputation: 8035

The reason this happens is that the main part of the page isn't allowed to take focus away from the dev tools window, so when you're in the console tab, the main part of the page can't take focus away from it.

Very annoying, run your code in a script and it should work.

Upvotes: 9

Related Questions