get-parent-by-selector

Returns the nearest parent element which maches a css selector

Usage no npm install needed!

<script type="module">
  import getParentBySelector from 'https://cdn.skypack.dev/get-parent-by-selector';
</script>

README

get-parent-by-selector

Returns the first found parent of an element, queried by css selector.

<div class="parent">
    <section ... />
    <section ... />
    <section>
        <a class="child" ... />
    </section>
</div>

----

let parent = parentBySelector(document.querySelector('.child'), '.parent');

Michael Jasper mdjasper@gmail.com