matchesSelector

Jump to: navigation, search

matchesSelector

This article is In Progress.


W3C Working Draft

Summary

The matches API checks if an element matches a given selector. While the old API used the name matchesSelector, the new one will use matches.

Method of dom/HTMLElement

Syntax

var result = element.matchesSelector(see parameter list);

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 Node.

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

Needs Examples: This section should include examples.

{{Notes_Section |Usage=Currently, no browser vendor supports the unprefixed version. It is recommended to use the API as following:

var docEl = document.documentElement,
    matches = docEl.matches
}}
{{Related_Specifications_Section
|Specifications=
}}
{{Compatibility_Section
|Not_required=No
|Imported_tables=
|Desktop_rows=
|Mobile_rows=
|Notes_rows=
}}
{{See_Also_Section}}
{{Topics|DOM}}
{{External_Attribution
|Is_CC-BY-SA=No
|Sources=MDN, MSDN
|MDN_link=https://developer.mozilla.org/en-US/docs/Web/API/Element.mozMatchesSelector
|MSDN_link=[http://msdn.microsoft.com/en-us/library/ie/hh828809%28v=vs.85%29.aspx Windows Internet Explorer API reference]
|HTML5Rocks_link=
}}