Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var sys = require('sys');
var browser = require('jsdom/browser')
var domToHtml = require('jsdom/browser/domtohtml').domToHtml;
var DOM = browser.browserAugmentation(require('jsdom/level2/core').dom.level2.core)
var doc = new DOM.Document('html');
doc.appendChild(doc.createElement('html'));
var headEl = doc.createElement('head');
doc.documentElement.appendChild(headEl);
var metaEl = doc.createElement('meta');
headEl.appendChild(metaEl);
metaEl.setAttribute('charset', 'utf-8');
var linkEl = doc.createElement('link');
headEl.appendChild(linkEl);
linkEl.setAttribute('href', '/foo.css');
var bodyEl = doc.createElement('body');
doc.documentElement.appendChild(bodyEl);
var h1El = doc.createElement('h1');
bodyEl.appendChild(h1El);
h1El.setAttribute('class', 'foo');
h1El.id = "bar";
h1El.appendChild(doc.createTextNode("hello, world"));
sys.puts(domToHtml(doc));
/* When run, this is what I'm seeing:
<html>
<head>
<meta>
</meta>
<link>
</head>
<body>
<h1>hello, world</h1>
</body>
</html>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.