563 B
563 B
title, tags
| title | tags |
|---|---|
| elementContains | browser,intermediate |
Checks if the parent element contains the child element.
- Check that
parentis not the same element aschild. - Use
Node.contains()to check if theparentelement contains thechildelement.
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