set cursor position

Asked

Viewed 49 times

0

it is possible to define where the cursor will look as soon as the user enters a screen ?

For example, I have this input, as I define that whenever the screen is logged in or loaded, the cursor is in this input:

<input id="itemsearch" placeholder="Pesquisar" aria-label="Search">

Thank you

  • 1

    Determining the mouse position on the screen is not possible. Use the attribute autofocus in your input element to give it a focus when the page is loaded, it would look like this <input id="itemsearch" placeholder="Pesquisar" aria-label="Search" autofocus> or depending on what you’re doing use the Javascript function focus() in the specified element, this will give the same result.

  • 1

    @leandrodonascimento is exactly that, thank you very much for the help.

1 answer

0

It is not possible to determine the position of the cursor (mouse) relative to the screen. However it is possible to put the focus on a certain field, which seems to be what you want to know. In this case, just run the following at the time you need to determine the focus:

document.getElementById('itemsearch').focus();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.