Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 1.05 KB

elementContains.md

File metadata and controls

29 lines (24 loc) · 1.05 KB
title tags author_title author_url author_image_url description image
elementContains
browser,intermediate
Deepak Vishwakarma
Implementation of "elementContains" in typescript, javascript and deno.

JS TODO

Returns true if the parent element contains the child element, false otherwise.

Check that parent is not the same element as child, use parent.contains(child) 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