701 B
701 B
title, tags, expertise, cover, firstSeen, lastUpdated
| title | tags | expertise | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| Element contains another element | browser | intermediate | blog_images/red-petals.jpg | 2018-06-19T20:57:58+03:00 | 2020-11-03T22:11:18+02:00 |
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