0

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

John Conde
  • 212,985
  • 98
  • 444
  • 485
Ken Hirakawa
  • 7,151
  • 10
  • 36
  • 49

3 Answers3

0

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

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
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
  • 319,460
  • 37
  • 290
  • 318
  • 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
  • 325,660
  • 70
  • 395
  • 481
  • 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