Miss any of our Open RFC calls?Watch the recordings here! »

nextmatchingelement

1.0.1 • Public • Published

nextMatchingElement

Find the next matching sibling element in the DOM

npm version
NPM

NPM

npm install nextmatchingelement --save

Usage

With Commonjs/Browserify/Webpack

var nextEl = require('nextmatchingelement');
 
nextEl(el, target, callback);

Parameters

el

el is the starting element, from which the sibling will be found.

target

target is the target element you'd like to select

callback

callback is the callback function you'd like to run once the target element has been found. It takes one argument which is a DOM node of the nextElementSibling found.

Example usage

With HTML like this

    <h3 class="findNext"></h3>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sit dolore commodi, et fuga quas.</p>
    <div class="demo">
        Foo
    </div>

Use JS like this

var findNext = document.querySelector('.findNext');
nextEl(findNext, 'demo', function (target) {
    target.classList.toggle('show-code');
});

Install

npm i nextmatchingelement

DownloadsWeekly Downloads

32

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar