Day 36 of #100daysofjs

matches, closest and contains

There are three important methods to search the DOM

  1. elem.matches (CSS) -> To check if elements matches the given CSS selection.

  2. elem.closest (CSS) -> To look for the nearest ancestor that matches the given CSS selector. The elem itself is also checked.

  3. elemA.contains (elemB) -> Returns true if elemB is inside elemA ( a descendant of elemA ) or when elemA == elemB.