npm install nextmatchingelement --save
var nextEl = require('nextmatchingelement');
nextEl(el, target, callback);
el
is the starting element, from which the sibling will be found.
target
is the target element you'd like to select
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.
<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>
var findNext = document.querySelector('.findNext');
nextEl(findNext, 'demo', function (target) {
target.classList.toggle('show-code');
});