range-iterator
v2.0.0
Published
ES6 Iterator that iterates over the Nodes of a Range
Downloads
22
Readme
range-iterator
ES6 Iterator that iterates over the Nodes of a Range
Installation
$ npm install range-iterator
Example
import RangeIterator from 'range-iterator';
let range = document.createRange();
range.selectNodeContents(document.body);
// Iterate over all TextNodes and BR elements within the Range selection
let iterator = RangeIterator(range, NodeFilter.SHOW_ALL, function (node) {
return node.nodeType === Node.TEXT_NODE || node.nodeName === 'BR';
})
let node;
for (node of iterator) {
// do something with Node `node`
console.log(node);
}