From 1b66a3dd73398e2629f2bd2b57c34ca41f9b5ce0 Mon Sep 17 00:00:00 2001 From: morethanwords Date: Thu, 15 Apr 2021 15:02:29 +0400 Subject: [PATCH] Fix replace content --- src/helpers/dom.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helpers/dom.ts b/src/helpers/dom.ts index e0eec949..77c8579c 100644 --- a/src/helpers/dom.ts +++ b/src/helpers/dom.ts @@ -682,12 +682,15 @@ export function htmlToSpan(html: string) { export function replaceContent(elem: HTMLElement, node: string | Node) { // * children.length doesn't count text nodes - if(elem.children.length) { - elem.firstChild.replaceWith(node); - } else if(!elem.firstChild) { - elem.append(node); + const firstChild = elem.firstChild; + if(firstChild) { + if(elem.lastChild === firstChild) { + firstChild.replaceWith(node); + } else { + elem.textContent = ''; + elem.append(node); + } } else { - elem.textContent = ''; elem.append(node); } }