Fix replace content
This commit is contained in:
parent
1de9861f30
commit
1b66a3dd73
@ -682,12 +682,15 @@ export function htmlToSpan(html: string) {
|
|||||||
|
|
||||||
export function replaceContent(elem: HTMLElement, node: string | Node) {
|
export function replaceContent(elem: HTMLElement, node: string | Node) {
|
||||||
// * children.length doesn't count text nodes
|
// * children.length doesn't count text nodes
|
||||||
if(elem.children.length) {
|
const firstChild = elem.firstChild;
|
||||||
elem.firstChild.replaceWith(node);
|
if(firstChild) {
|
||||||
} else if(!elem.firstChild) {
|
if(elem.lastChild === firstChild) {
|
||||||
elem.append(node);
|
firstChild.replaceWith(node);
|
||||||
|
} else {
|
||||||
|
elem.textContent = '';
|
||||||
|
elem.append(node);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
elem.textContent = '';
|
|
||||||
elem.append(node);
|
elem.append(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user