This helped me figure out how to process some keyboard commands in a tree container div. By assigning a keypress event handler to a div with a tabIndex value, I was able to add keyboard commands to a hierarchical data editor.
–
David LivelySep 4 '09 at 15:32

Perfect! Yours is the best solution in terms of being simple. I like simple stuff. I prefer to avoid a script if it can be done without it.
–
Marcos BuarqueOct 21 '09 at 17:41

This was a great solution. Thank you very much.
–
Corv1nusAug 3 '11 at 20:26

4

You should use tabindex="0" if you don't want to disturb the order of the tabs in the page. If you only want to give focus with Javascript, and make the div not focusable, put tabindex="-1". Tabindex -1 can receive focus by Javascript, but not by hitting the tab key.
–
dturcotteJun 1 '12 at 15:04

Only form elements and such can attain focus. If you want the browser to scroll down to that particular paragraph, there is no "default" way of doing so with jQuery, but there is a plugin for it at jQuery.ScrollTo and a blog explaining how to do it manually at Animated scroll with jQuery