title | tags |
---|---|
elementContains |
browser,intermediate |
Returns true
if the parent
element contains the child
element, false
otherwise.
- Check that
parent
is not the same element aschild
, useparent.contains(child)
to check if theparent
element contains thechild
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