luke
luke

Reputation: 3599

:valid and :invalid selectors in jQuery

In jQuery 3.2.1, calling below expressions returns "undefined" (for both):

typeof $.expr[":"]["valid"]
typeof $.expr[":"]["invalid"]

However, it is possible to call $(":valid") or $(":invalid") and in the example below, it seems that these selectors return inputs that have valid or invalid value. It is not mentioned in the documentation that these selectors exist.

Please check this example for clarification.

Upvotes: 3

Views: 1321

Answers (2)

BoltClock
BoltClock

Reputation: 724592

jQuery does not contain its own implementation of the :valid and :invalid selectors. These selectors work in jQuery through the browser's native implementation of the standard via document.querySelectorAll().

This also implies that $(":valid") and $(":invalid") will not work in browsers that don't support these selectors, such as Internet Explorer 8 (incidentally the only such browser that does implement querySelectorAll()) and older.

Upvotes: 4

Suresh Ponnukalai
Suresh Ponnukalai

Reputation: 13998

:valid and :invalid are not a jquery selectors. It is a CSS3 selectors. It is defined in the CSS Selectors Level 3 spec as a “validity pseudo-selector”, meaning it is used to style interactive elements based on an evaluation of user input.

You can get more clarity from the following url.

CSS Selector :invalid

Upvotes: 2

Related Questions