Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.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.

like image 429
cerberos Avatar asked Feb 17 '23 00:02

cerberos


1 Answers

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.

like image 95
cerberos Avatar answered Feb 23 '23 09:02

cerberos