Similar Question:
Check if event target parent element matches selector in JavaScript
I have a DOM element that I want to compare with all its parent elements against a specific selector, similar to the functionality of jQuery's .parents('selector') method. However, I do not require backwards compatibility and prefer not to use any libraries. I am specifically looking for a method that returns a boolean value.
I can create a recursive function, loop, or while statement using matchesSelector() myself, but I am interested in discovering lesser-known methods or more efficient code. The goal is to save process time, especially when dealing with tens of thousands of matching checks or even more.