getnextuntil

0.0.6 • Public • Published

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.

Package Sidebar

Install

npm i getnextuntil

Weekly Downloads

1

Version

0.0.6

License

ISC

Unpacked Size

110 kB

Total Files

6

Last publish

Collaborators

  • jonbloomer