Input vs :Input in jQuery

前端 未结 3 2004
清歌不尽
清歌不尽 2021-02-13 11:43

I wonder why people seems to prefer :input over input as a jQuery selector? Basically, this two lines seem to do the same thing :

$(\'i         


        
相关标签:
3条回答
  • 2021-02-13 12:03

    input is just the input element selector. :input also selects textarea, select, and button (form controls).

    It's not necessarily a matter of preference since in actuality they do somewhat different things.

    0 讨论(0)
  • 2021-02-13 12:11

    :input selects all input, textarea, select and button elements, while input just selects elements with an input tag.

    0 讨论(0)
  • 2021-02-13 12:14

    :input is pseudo selector by jQuery which includes <buttons>, <textarea>, e.t.c

    input is a tag match which strictly matches <input>.

    This additional note about :input is informative:

    Because :input is a jQuery extension and not part of the CSS specification, queries using :input cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :input to select elements, first select the elements using a pure CSS selector, then use .filter(":input").

    --from https://api.jquery.com/input-selector/

    0 讨论(0)
提交回复
热议问题