DOM Element.matches() Method
The matches() method checks whether an element would be selected by a given CSS selector.
Description
The matches() method tests whether the element would be selected by the given CSS selectors. It's useful in event handlers and filters, for example checking whether an element is :checked, has a class or matches a media-dependent state like :hover.
It accepts the same selectors as querySelector(), including complex ones such as 'nav a:not(.active)', and throws a SyntaxError for invalid selectors. Unlike closest(), it only checks the element itself.
A common use is filtering event targets in delegated listeners, such as if (e.target.matches('.delete')) ..., and checking pseudo-classes that reflect state, such as :focus-visible, :invalid or :popover-open.
Syntax
element.matches(selectors)Parameters
- selectorsA string of one or more CSS selectors.
Return Value
true if the element matches the selectors, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the Element.matches() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





