Fix replace content
This commit is contained in:
parent
be1bd0bcde
commit
a57599f3a2
1
public/0.3284cf71eacdcef4f4a6.chunk.js
Normal file
1
public/0.3284cf71eacdcef4f4a6.chunk.js
Normal file
File diff suppressed because one or more lines are too long
BIN
public/0.3284cf71eacdcef4f4a6.chunk.js.gz
Normal file
BIN
public/0.3284cf71eacdcef4f4a6.chunk.js.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user