This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

matches

Summary

Returns true if an element matches a given selector. Otherwise, false.

Method of dom/HTMLElementdom/HTMLElement

Syntax

var result = element.matches(selector);

Parameters

selector

Data-type
String

This string represents the selector to test the element against. This parameter is required and it must have a length of at least one. An empty string throws the error Dom Exception 12.

Return Value

Returns an object of type DOM NodeDOM Node

Returns true if the element matches the given selector or false if it doesn’t.

Usage

 Currently, few browsers support the unprefixed version. It is recommended to use the API as following:

var docEl = document.documentElement,
    matches = docEl.matches || docEl.webkitMatchesSelector || docEl.mozMatchesSelector || docEl.msMatchesSelector || docEl.oMatchesSelector;
matches.call(element, selector)

Attributions