Does there exist some trick other than tabindex attribute so that a div can get focus ?
Asked
Active
Viewed 885 times
0
-
2Why do you want to give focus to a div element? – rahul Dec 22 '09 at 07:58
-
May be a duplicate of http://stackoverflow.com/questions/334489/jquery-focus – APC Dec 22 '09 at 08:02
-
I am using a div as an editor (not as a text editor ). It will contain various small images which should listen some keyboard events when parent div'll be selected – Tinku Dec 22 '09 at 08:03
-
3I'm not sure focusing a `div` will work in all browsers. – Pekka Dec 22 '09 at 08:05
1 Answers
3
Setting contenteditable="true"
will also allow a div to receive focus in browsers that support it (IE 5.5+, Firefox 3.0+, WebKit for a few years, not sure about Opera), though obviously with the side effect of making the div editable by the user.
<div contenteditable="true">Tab to me</div>

Tim Down
- 318,141
- 75
- 454
- 536