0.0.2 • Published 6 years ago

query-parent-element v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

query-parent-element

Get aim parent element

npm: query-parent-element CircleCI Coverage Status tested with jest code style: prettier license: mit TypeScript

Install or Download

yarn add [-D] query-parent-element

Example

As it is this kind of HTML

<div id="parent">
  <div>
    <div>
      <div id="child">
      </div>
    </div>
  </div>
</div>

If on the browser

<script src="//unpkg.com/query-parent-element/dist/query-parent-element.js"></script>
import queryParentElement from 'query-parent-element';

// (child: string | HTMLElement, parent: string | HTMLElement) => HTMLElement | undefined;
const result = queryParentElement(
  document.getElementById('child') /* or '#child' */,
  document.getElementById('parent') /* or '#parent' */
);

if (result !== undefined) {
  console.log(result); // <div id="parent"/>
}