0.0.6 • Published 6 years ago

getnextuntil v0.0.6

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Build Status

getNextUntil

This is a packaged version of the Chris Ferdinandi utility function that gets all next siblings of an element in the DOM until a selector is found.

Installation

npm i getnextuntil

Usage

Given the following markup:

<ul>
	<li>Item 1</li>
	<li class="stop-here">Item 2</li>
	<li>Item 3</li>
	<li>Item 4</li>
	<li id="find-me">Item 5</li>
	<li>Item 6</li>
	<li>Item 7</li>
	<li class="stop-here">Item 8</li>
	<li>Item 9</li>
</ul>
import getnextuntil from 'getnextuntil'

var findMe = document.querySelector('#find-me');

// Returns the first two list items after #find-me
var nextStop = getNextUntil(findMe, '.stop-here');

// Returns all list items after #find-me
var nextAll = getNextUntil(findMe);

The matches() method was implemented inconsistently with vendor prefixes across many browsers for a while. You should include a polyfill for it to make sure these work properly.