JSFiddle - React, Tailwind, and code Playground

by patrick_dw

HTML

<ul>
    <li id='one'>one</li>
    <li id='two'>two</li>
    <li id='three' class='a'>three</li>
    <li id='four' class='a'>four</li>
</ul>

JavaScript

(function( $ ) {
    $.fn.nextMatch = function( func ) {
        return this.map(function() {
            var el = this;
            while( el = el.nextElementSibling ) {
                if( func.call( el ) ) {
                    return el;
                }
            }
        });
    }
})( jQuery );

var someEl = $('#one');

var nextEl = someEl.nextMatch( function() {
    return (this.className === 'a');
});

alert(nextEl.attr('id'));