Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .focus() not working without tabindex attribute of div

Tags:

jquery

How can I make jquery .focus() to work without setting tabindex of a div

  $("#msgdiv").focus();

<div id="msgdiv" tabindex="100"> </div>

what is the best practise for this

what i want to achieve: After changing the password i want to display the acknowledgment message that the password has been changed and put focus on that div.

like image 881
maztt Avatar asked Apr 08 '11 11:04

maztt


1 Answers

Simply, you can't do focus on a div without tabindex, see documentation.

Don't really know what you wanna achieve with this code-snippet, but if you wanna trigger a focus event, you should use trigger:

$("#msgdiv").trigger('focus');
like image 61
Kristoffer Lundberg Avatar answered Sep 19 '22 19:09

Kristoffer Lundberg