Last active
November 18, 2019 00:10
-
-
Save BeFiveINFO/f711e36dedf3f27bc6f82d7865a521a0 to your computer and use it in GitHub Desktop.
JSDOM appendChild sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $Fs = require('fs'); | |
const { JSDOM } = require('jsdom'); // uninstall when done | |
const htmlText = ` | |
<div id="target"> | |
<p>test</p> | |
</div> | |
`; | |
const _htmlTextDom = new JSDOM(htmlText); | |
const _htmlTextDomDocument = _htmlTextDom.window.document; | |
const target = _htmlTextDomDocument.querySelector('div#target'); | |
const div = _htmlTextDomDocument.createElement("div"); | |
div.innerHTML = "<p>Hello</p>"; | |
target.appendChild(div); | |
console.log(_htmlTextDomDocument.body.innerHTML); | |
/* Expected output | |
<div id="target"> | |
<p>test</p> | |
<div> | |
<p>Hello</p> | |
</div> | |
</div> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment