How to activate autofocus with jquery on a div?

0

How to activate autofocus with jquery on a div? I want to do an autofocus in an input once the user does such action ...

    
asked by anonymous 24.10.2017 / 21:28

1 answer

5

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>
    
24.10.2017 / 22:32