JSFiddle - React, Tailwind, and code Playground
JavaScript
var doc = document.implementation.createHTMLDocument('Title');
var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
body.setAttribute('id', 'myBody');
doc.documentElement.appendChild(body);
// create new elements using the local document
var div = document.createElement('div');
div.setAttribute('id', 'myDiv');
var content = document.createTextNode("Hello world!");
div.appendChild(content);
body.appendChild(div);
// or create new elements using the local document
var div = doc.createElement('div');
div.setAttribute('id', 'myDivNew');
var content = doc.createTextNode("Hello world!");
div.appendChild(content);
body.appendChild(div);
console.log('div created with local document: ', doc.getElementById('myDiv'));
console.log('div created with new document: ', doc.getElementById('myDivNew'));
console.log(doc.getElementById('myBody'));