findDescendant
Search all descendants of some root element for the first element matching the passed in condition.
The starting element that triggers this search is not included in the search.
This search runs in a breadth-first search manner. If not specified, the search starts from the document's body
element.
For example, perhaps you want to find a close button that's part of a popup dialog that you're inside. The close button also lives inside the dialog, but you are not a direct ancestor.
ElementTarget.findDescendant(root = dialogElement) { it.classList.contains("close-button") }
Parameters
The root to start searching descendants for. This should never be set to null, but its API accepts a nullable parameter so that it can default to document.body
, which itself is nullable (even though a body will almost always exist). If set to null, the descendant search will always fail.