Which is why I said "short answer". Long answer: You can set a tabindex for a div, and you don't need to resort to JavaScript to do it:
<div id="mydiv" tabindex="1"></div> But doing so is not a good idea, IMO. According to the W3C the following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA. http://www.w3.org/TR/html401/interact/forms.html#adef-tabindex Browsers allow other elements to have a tabindex, but with unpredictable results. Tabindex (and accesskey) is intended primarily for those elements that the user directly interacts with, that is where tabbing to and then using control/enter keys, etc. Again, according to the W3C "In an HTML document, an element must receive focus from the user in order to become active and perform its tasks". DIVs don't perform tasks, they are grouping elements, this is why you don't see onfocus() and onblur() events associated with them http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#edef-DIV Although browsers will allow you attach focus() and blur() events to an element that isn't intended to receive them (with the addition of tabindex), the results can be upredictable. Firefox in particular can fire the blur and focus events in the wrong order. It also shows wierdness when a focusable element (such as an input or anchor) is contained within an element not normally focusable (e.g. a div) but made so by the addition of a tabindex attribute. In short, what browsers allow you to do, and what you SHOULD do are two different things. My suggestion is refactor your code to not rely on a DIV having or not having focus. On Mar 5, 8:22 pm, Karl Swedberg <k...@englishrules.com> wrote: > On Mar 5, 2009, at 11:01 PM, mkmanning wrote: > > > short answer: DIVs can't receive focus() > > They can receive focus if they have a tabIndex property applied to > them. If, for example, you incremented each div's tabIndex, you could > then tab through them. > > $('div').each(function(index) { > $(this).attr('tabIndex', index+1); > > }); > > I wouldn't try this with just "div" in the selector, though, if you > have a fairly complex page. > > --Karl > > ____________ > Karl Swedbergwww.englishrules.comwww.learningjquery.com