1.0.0 • Published 3 years ago

@jswork/next-dom-find-ancestor v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

next-dom-find-ancestor

Find the closest ancestor element that has a specific class.

version license size download

installation

npm install -S @jswork/next-dom-find-ancestor

usage

<div class="far ancestor">
    <div id="target2">
      <div class="near ancestor">
          <p id="target1">Where am I?</p>
      </div>
    </div>
</div>
import '@jswork/next-dom-find-ancestor';

const el1 = document.querySelector('#target1');
const el2 = document.querySelector('#target2');

nx.domFindAncestor(el1, '.ancestor'); // near
nx.domFindAncestor(el2, '.ancestor'); // far

resources

license

Code released under the MIT license.