Menu

gitpiper

elementContains javascript Code Snippet in 2024

browserintermediate

Last Updated: 20 April 2024

Checks if the parent element contains the child element.

  • Check that parent is not the same element as child.
  • Use Node.contains() to check if the parent element contains the child element.
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

javascript snippet similar to elementContains For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️