@jswork/next-dom-find-ancestor

Find the closest ancestor element that has a specific class.

Usage no npm install needed!

<script type="module">
  import jsworkNextDomFindAncestor from 'https://cdn.skypack.dev/@jswork/next-dom-find-ancestor';
</script>

README

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.