zip-text-nodes
Merge the DOM of 2 elements with the same textContent.
Given 2 elements:
Hello, world!
and:
Hello, world!
they are merged into:
Hello, world!
This can be useful when running some transformations on the content of an element and successively merging the results or restoring the original markup.
const base = <>I live in <a href="it">Italy</a></>;const grammar = ;// <>I <em>live</em> in Italy</> // e.g. the link was lost ;// <>I <em>live</em> in <a href="it">Italy</a></>// The new `em` is copied from `grammar` to `base`
Supports overlapping and nested elements.
Install
npm install zip-text-nodes
Setup
const zipTextNodes = ;
;
API
zipTextNodes(target, source)
target
Type: Element
DocumentFragment
The element into which the new children are copied. This element is modified.
source
Type: Element
DocumentFragment
The element from which the new children are copied.
Related
- insert-text-textarea - Insert text in a textarea (supports Firefox and Undo).
- fit-textarea - Automatically expand a
<textarea>
to fit its content, in a few bytes. - delegate-it - DOM event delegation, in <1KB.