wrap-range

2.0.3 • Public • Published

wrap-range

Wraps a DOM Range instance with the specified DOM node name

Sauce Test Status

Build Status

Installation

$ npm install wrap-range

Example

var wrapRange = require('wrap-range');
 
// create a DIV with some content
var div = document.createElement('div');
div.innerHTML = 'hello world';
 
// append it to the page
document.body.appendChild(div);
 
// create a Range instance pointing to some of the text
var range = document.createRange();
range.setStart(div.firstChild, 1);
range.setEnd(div.firstChild, 8);
 
// now we can "wrap" the Range with an element node type,
// say U to underline in this case:
var uNodes = wrap(range, 'u');
 
assert.equal(uNodes.length, 1);
assert.equal(uNodes[0].nodeName, 'U');
assert.equal(uNodes[0].innerHTML, 'ello wo');
 
assert.equal(div.innerHTML, 'h<u>ello wo</u>rld');

Package Sidebar

Install

npm i wrap-range

Weekly Downloads

1

Version

2.0.3

License

MIT

Last publish

Collaborators

  • tootallnate