Merging Text Nodes Together After Inserting Span

Use element.normalize().

After you remove the span you inserted, you can use the element.normalize() method to merge the extra text nodes that were created as a result of the insertion/removal of the span. The normalize() method puts the specified element and all of its subtree into a “normalized” form (i.e. no text nodes in the subtree are empty and there are no adjacent text nodes). Found, thanks to @tcovo’s comment.

Text nodes inside of an element are broken apart if you insert nodes and then remove them. Unfortunately they don’t automatically re-merge once the extra node is removed. To answer peoples’ questions as to “why” this matters, it usually causes issues when working with text highlighting in your UI.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)