You can try the following with these version settings in your package.json:
"jquery": "^2.1.1", "jsdom": "^1.0.0-pre.3"
Say you have a file called page.htm:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <h1>Html page</h1> <div class="left"> <p>left content</p> </div> </body> </html>
Then, you can read from file, create a DOM and window from it with JSDOM and pass it to jquery:
var jsdom = require("jsdom").jsdom; var fs = require('fs'); fs.readFile('page.htm', {encoding: "utf8"}, function (err, markup) { if (err) throw err; var doc = jsdom(markup); var window = doc.parentWindow; var $ = require('jquery')(window) var outerLeft = $(".left").clone().wrap('<div></div>').parent().html(); var innerLeft = $(".left").html(); console.log(outerLeft, "and ...", innerLeft); });
will output:
<div class="left"> <p>left content</p> </div> and ... <p>left content</p>