0
How to enable autofocus with jquery in a div? I want to autofocus an input as soon as the user does such an action...
0
How to enable autofocus with jquery in a div? I want to autofocus an input as soon as the user does such an action...
6
Just use the function focus
jQuery when you want to focus on the field. For example, focus on a text field by clicking the button:
$(() => {
$("#btn").on("click", event => {
$("#nome").focus();
console.log("O campo está em foco.");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="nome" type="text">
<button id="btn">Foco</button>
Browser other questions tagged jquery
You are not signed in. Login or sign up in order to post.
The autofocus would be to give focus when loading the page. If it is after an action, just you give the focus in the field by doing
$("seu campo").focus()
– Woss
THAT DELICIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA VALEUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
– Edenilson Conceição
As a complement to what has already been answered by @Andersoncarloswoss and although not focusing on the tag, you can do the same only with html using the attribute
autofocus
, which will work like Focus when opening the page.– Isac