check if the parent element contains the child element

PHOTO EMBED

Sat Feb 26 2022 02:15:21 GMT+0000 (Coordinated Universal Time)

Saved by @mboljar

const elementContains = (parent, child) => parent !== child && parent.contains(child);

// Examples
elementContains(document.querySelector('head'), document.querySelector('title')); 
// true
elementContains(document.querySelector('body'), document.querySelector('body')); // false
content_copyCOPY

https://madza.hashnode.dev/24-modern-es6-code-snippets-to-solve-practical-js-problems?guid