Easy Tutorial
❮ Prop Audio Seekable Met Element Removeattributenode ❯

HTML DOM matches() Method

Element Object

Example

Does the element match the CSS selector?

const element = document.getElementById("demo");
let answer = element.matches(".container");

Example

Does the element match one of two CSS selectors?

const element = document.getElementById("demo");
let answer = element.matches(".container, .wrapper");

Definition and Usage

The matches() method returns true if the element matches the specified CSS selector; otherwise, it returns false.


Browser Support

The numbers in the table specify the first browser version that fully supports the matches() method:

Chrome <br>33 Edge <br>15 Firefox <br>34 Safari <br>7 Opera <br>21
Feb 2014 Apr 2017 Dec 2014 Oct 2013 May 2014

Syntax

element.matches(selectors)

Parameters

| Parameter | Description | | selectors | Required. <br>One or more (separated by commas) CSS selectors to match against. <br>The returned element is the first found in the HTML document. <br> <br>See all CSS Selectors Reference |

Return Value

Type Description
Boolean true - The element matches the CSS selector. false - The element does not match the CSS selector.

Element Object

❮ Prop Audio Seekable Met Element Removeattributenode ❯