HTML DOM Element matches() method
- Previous page lastElementChild
- Next page namespaceURI
- Go up one level HTML DOM Elements object
Definition and usage
matches()
The method will return true
, if the element matches a specific CSS selector; otherwise return false
.
See also:
Example
Example 1
Does the element match a CSS selector?
const element = document.getElementById("demo"); let answer = element.matches(".container");
Example 2
Does the element match one of the two selectors?
const element = document.getElementById("demo"); let answer = element.matches(".container, .wrapper");
Syntax
element.matches(selectors)
Parameter
Parameter | Description |
---|---|
selectors |
Required. One or more (comma-separated) CSS selectors to match. The returned element is the first element found in the document. Please see our complete CSS selector reference manual. |
Return value
Type | Description |
---|---|
Boolean value |
|
Browser support
First fully supported matches()
Browser version of the method:
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 33 |
Edge 15 |
Firefox 34 |
Safari 7 |
Opera 21 |
2014 February | 2017 April | 2014 December | October 2013 | May 2014 |
- Previous page lastElementChild
- Next page namespaceURI
- Go up one level HTML DOM Elements object