Skip to content

Instantly share code, notes, and snippets.

@iceener
Created July 3, 2020 13:50
Show Gist options
  • Save iceener/c150e68e324fc88d5531e4d30f309370 to your computer and use it in GitHub Desktop.
Save iceener/c150e68e324fc88d5531e4d30f309370 to your computer and use it in GitHub Desktop.
// Check if the element contains another element
const contains = (element, child) => element !== child && element.contains(child);
const element = document.querySelector('.parent');
const child = document.querySelector('.child');
contains(element, child); // true | false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment