Is there a jQuery selector to get all elements that can get focus?

前端 未结 8 596
故里飘歌
故里飘歌 2020-12-01 15:54

This answer tells which HTML elements can receive focus. Is there a jQuery selector that matches exactly these elements?

For now I\'m just using $(\'input,sele

8条回答
  •  一向
    一向 (楼主)
    2020-12-01 16:33

    You could check for elements that have the focus() function:

    $('*').each(function() {
      if(typeof this.focus == 'function') {
        // Do something with this element
      }
    }) ;
    

    Edit Thinking a little more, it would probably makes sense to have *:visible rather than just * as the selector for most applications of this.

提交回复
热议问题