0.0.2 • Published 6 years ago
query-parent-element v0.0.2
query-parent-element
Get aim parent element
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"/>
}