0

If a dom element is :visible, will it always be focussable?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Ken Hirakawa
  • 7,831
  • 10
  • 38
  • 49

3 Answers3

0

No. You can't (for instance and by default) focus a div.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

It's not guaranteed, but you can check to see if an element will fire the focus event.

var focussableEls = [];
$(":visible").each({
    if (typeof this.focus == 'function')
        focussableEls.push(this.id);
});
console.log(focussableEls);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • That appears to come back with html, body and every element in the body, not just those that can be focused. http://jsfiddle.net/TEL4J/ – Quentin May 01 '12 at 15:15
0

Check for elements that have a tabindex attribute:

$('[tabindex]')
Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • Elements don't have to have a tabindex attribute to be focusable (e.g. an input element is focusable by default). – Quentin May 01 '12 at 15:11