I have an array from a parse
odg = tinymce.activeEditor.getContent({ format: "HTML" });
const parser = new DOMParser();
const parsedDocument = parser.parseFromString(odg, "text/html");
const parsedContent = parsedDocument.querySelectorAll(
"body:not(first-child) > *"
);
let array2 = Array.from(parsedContent);
I get:
Array [ p, ul]
0: <p>
1: <ul>
length: 2
<prototype>: Array []
When I change into string
let contentString = array2.join("");
I get:
[object HTMLParagraphElement][object HTMLUListElement]
Instead of: <p>something</p><ul><li>something else</li></ul>
What am I missing?
CodePudding user response:
You can access outerHTML
let odg = document.querySelector('container').innerHTML
const parser = new DOMParser();
const parsedDocument = parser.parseFromString(odg, "text/html");
const parsedContent = parsedDocument.querySelectorAll(
".findme > *"
);
let array2 = Array.from(parsedContent);
console.log(array2.map(m => m.outerHTML).join(''));
<container>
Ignore me
<div class='findme'>
<div>This </div>
<p>That</p>
</div>
</container>