Web APIs

Element.matches()

Try the free JavaScript compiler

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

NameTypeDescription
selectorsstringCSS 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"));
JavaScript Reference