dom-siblings

Find a DOM element's siblings, optionally filtered by a CSS selector.

Usage no npm install needed!

<script type="module">
  import domSiblings from 'https://cdn.skypack.dev/dom-siblings';
</script>

README

dom-siblings

Build Status

Find a DOM element's siblings, optionally filtered by a CSS selector.

Installation

npm install dom-siblings

API

siblings(element, selector)

  • element: a DOM Element.
  • selector: a CSS selector string.
var siblings = require('dom-siblings');
var element = document.querySelector('div');

siblings(element);
// => [Element, Element]
// all sibling elements

siblings(element, '.foo');
// => [Element]
// all sibling elements with class 'foo'

Browser support

  • Google Chrome
  • Firefox 4+
  • Internet Explorer 8+
  • Safari 5+
  • Opera