Move Cursor Focus to DIV element using jQuery

Sometimes we need to move user focus on specific position for do focus their attention. i hope you know about .focus in jQuery and already used it to set cursor focus in input Textbox, TextArea etc.

Here, im going to show you how to set focus on Div element. to set focus on DIV id its required to DIV element has tabindex property with -1 value. without tabindex property below code never move your cursor focus to that DIV element.

<div id="mydiv" tabindex="-1">
</div>


jQuery for move focus

<script type="text/javascript">

jQuery('#mydiv').focus();

</script>
Alternative if you cant add tabindex="-1" attribute to your Div in which you want to set focus than use below syntax which do almost same as above
<script type="text/javascript">

jQuery("#mydiv").attr("tabindex",-1).focus();

</script>
for more detail on .focus() JavaScript event visit jQuery Focus Leave comment in below if you get it working by any other method or need help :)

Post a Comment

1 Comments

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)