How to activate autofocus with jquery on a div? I want to do an autofocus in an input once the user does such action ...
How to activate autofocus with jquery on a div? I want to do an autofocus in an input once the user does such action ...
Just use the focus
function of 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><inputid="nome" type="text">
<button id="btn">Foco</button>