focus listener on non-form elements in Safari/Chrome

Discussion in 'Javascript' started by Gregor Kofler, Nov 6, 2008.

  1. Setting the tabIndex property an element makes it focusable and attached
    key listeners respond. Or so it seems...

    This procedure works in - from what I've tested - IE6+, FF, Opera.
    However, Safari and Chrome (and perhaps others) fail to respond,
    obviously myElement.focus() can be called, but shows no further effect.

    One possibility might be a listener attached to the document, which then
    redirects the event to the "focused" element - not really elegant.

    Did I overlook something, or does the tabIndex/focus trick simply not
    work in Safari/Chrome?

    Gregor Kofler, Nov 6, 2008
    1. Advertisements

  2. What is `myElement'? Not every element object has a focus() method to begin
    Dunno. Post your test case. (I guess you saw that coming ;-))

    Thomas 'PointedEars' Lahn, Nov 6, 2008
    1. Advertisements

  3. Thomas 'PointedEars' Lahn meinte:
    In this case an unordered list. Yes, they normally come without the
    focus handling ability and hence (though from my findings you can
    actually invoke a focus() method) the focus() method does nothing.

    However, as Martin Honnen pointed out a few days ago (topic "keydown
    listener for div"), setting a tabIndex for an element makes it magically
    focusable. MS documents that for IE5+ [1] and Firefox and Opera
    obviously followed (typeof element.focus() returns "function" also in
    Since "serious" libraries like extJS (e.g.[2]) can't cope with that
    either (and they've put in hundreds of kB finest JS, maybe even added
    some fancy browser sniffing...), I suppose it's just not easily fixed.
    It's the query popups in here:

    I don't have a reduced test case ATM.


    Gregor Kofler, Nov 6, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.