matches() method is used to check the element if it contains the given value or not.
If the value is present it returns true, else returns false.
Example - Check for given value
- In the above example we have added three paragraph each with different class names (cls1, cls2, cls3).
- When the program runs, in the script all the p elements are retrieved and stored in elem variable.
- Then using the for loop, we are checking if the each element in the loop whether it contains the specified element or not.