error404
error404

Reputation: 93

focus in a input field

After accepting the CPM I would like to have the cursor in the field that is in the center of this page: https://www.openthesaurus.de/?test=1 but unfortunately, every piece of code I try in the console doesn't work.

I've tried with

document.getElementById("search-field").focus()
document.getElementById("search-field").click()

and some other options that I've seen in some answers here, but none of them really worked.

Can someone provide me some light in this darkness?

Upvotes: 1

Views: 64

Answers (1)

Geuis
Geuis

Reputation: 42297

It actually is working. The problem is that your text focus is in the dev console.

To illustrate this, try the same thing but with a timeout. Paste and run this in your dev console, then quickly click into the page to give it focus. After a few seconds you'll see the input get focus.

setTimeout(() => document.querySelector('#search-field').focus(), 5000);

Upvotes: 1

Related Questions