Home > database >  Keep focus after click
Keep focus after click

Time:11-20

I can't find the jQuery method that allows me to apply a focus on an element and keep it until another element is clicked. A bit like toggle without the toggle effect. I tried toggleClass(); focusin(); focus();. The only one that worked was toggle but its behavior is not what I was looking for. A click on an element keeps the focus and remains active as long as there is no click on another element.

Any ideas?

Sorry, but I wasn't clear enough in my explanations. I want to keep the hover behavior on click and make it disappear when I click on another element. It is this method that I can't find.

CodePudding user response:

To apply a focus on an element you have to use the .focus() function without argument.

$('#my_element').focus();

It's a shortcut to

$('#my_element').trigger('focus');

CodePudding user response:

You can use .focus() method to keep focus on your input control.

 $("input:text").focus(); 
  • Related