Web APIs
Element.matches()
Test whether this element satisfies a CSS selector; invalid selector syntax throws. Example console output: true false.
Formal Syntax & Structure
javascript syntaxjavascript
element.matches(selectors)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| selectors | string | CSS selector list. |
Return Value
boolean
Whether the element matches.
Working Example
Example Snippetjavascript
const p=document.createElement("p"); p.className="note"; console.log(p.matches("p.note"),p.matches(".urgent"));