I wonder why people seems to prefer :input over input as a jQuery selector? Basically, this two lines seem to do the same thing :
$('input:first').focus()
$(':input:first').focus()
But second version is more widely use, and I don't find why. Moreover, the :input selector seem slower according to this benchmark: http://jsperf.com/input-vs-input/2
version added: 1.0jQuery( ":input" ) The :input selector basically selects all form controls.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
: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
:inputcannot take advantage of the performance boost provided by the native DOMquerySelectorAll()method. To achieve the best performance when using:inputto select elements, first select the elements using a pure CSS selector, then use.filter(":input").
--from https://api.jquery.com/input-selector/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With