Checks if the parent
element contains the child
element.
parent
is not the same element as child
.Node.contains()
to check if the parent
element contains the child
element.const elementContains = (parent, child) =>
parent !== child && parent.contains(child);
elementContains(
document.querySelector('head'),
document.querySelector('title')
);
// true
elementContains(document.querySelector('body'), document.querySelector('body'));
// false
JavaScript, Browser
Returns an array containing all the siblings of the given element.
JavaScript, Browser
Finds all the ancestors of an element up until the element matched by the specified selector.
JavaScript, Browser
Checks if the given element has the specified class.