

There is elem.matches(css) to check if elem matches the given CSS selector.There are 6 main methods to search for nodes in DOM: Methodīy far the most used are querySelector and querySelectorAll, but getElement(s)By* can be sporadically helpful or found in the old scripts.

The static collection did not increase after the appearance of a new div in the document. Let divs = document.querySelectorAll('div')

There are also other methods to look for nodes by a tag, class, etc. Let chapter = document.querySelector('.chapter') // LIĪlert(chapter.closest('.contents')) // DIVĪlert(chapter.closest('h1')) // null (because h1 is not an ancestor)
