Created
November 15, 2020 13:28
-
-
Save AitorAlejandro/3de983eeaabf27b43c9aabab84c93205 to your computer and use it in GitHub Desktop.
How to check if the parent element contains the child element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment