Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM matches() Method

  • Last Updated : 29 Jun, 2020

The matches() method checks if the Element that would be selected by the provided selectorString is the selector. If the specified element is the valid selector then it will return true, else false.


var boolean_result = element.matches("selector");

Parameters: Here, selector is used as a parameter.

Return value: It returns Boolean value i.e. (True when selector matches else false).

Example: In this example, there is a list in which there are some elements that have class selector as number. So, we stored the list in a variable and by iterating on the list, if selector matches number class, then printing on the document correspondingly.


<!DOCTYPE html>
        HTML DOM matches() Method
    <ul id="abc">
        <li class="number">1</li>
        <li class="number">2</li>
        var abc = document.getElementsByTagName('li');
        for (var i = 0; i < abc.length; i++) {
            if (abc[i].matches('.number')) {
                    + ' is not an alphabet ,  ');


Note: It is supported by all the browsers.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!