# jsdom A JavaScript implementation of the WHATWG DOM and HTML standards, for use with [io.js](https://iojs.org/). ## Install ```bash $ npm install jsdom ``` Note that as of our 4.0.0 release, jsdom no longer works with Node.js™, and instead requires io.js. You are still welcome to install a release in [the 3.x series](https://github.com/tmpvar/jsdom/tree/3.x) if you use Node.js™. ## Human contact - [Mailing list](http://groups.google.com/group/jsdom) - IRC channel: [#jsdom on freenode](irc://irc.freenode.net/jsdom) ## Easymode: `jsdom.env` `jsdom.env` is an API that allows you to throw a bunch of stuff at it, and it will generally do the right thing. You can use it with a URL ```js // Count all of the links from the io.js build page var jsdom = require("jsdom"); jsdom.env( "https://iojs.org/dist/", ["http://code.jquery.com/jquery.js"], function (errors, window) { console.log("there have been", window.$("a").length - 4, "io.js releases!"); } ); ``` or with raw HTML ```js // Run some jQuery on a html fragment var jsdom = require("jsdom"); jsdom.env( '
', ["http://code.jquery.com/jquery.js"], function (errors, window) { console.log("contents of a.the-link:", window.$("a.the-link").text()); } ); ``` or with a configuration object ```js // Print all of the news items on Hacker News var jsdom = require("jsdom"); jsdom.env({ url: "http://news.ycombinator.com/", scripts: ["http://code.jquery.com/jquery.js"], done: function (errors, window) { var $ = window.$; console.log("HN Links"); $("td.title:not(:last) a").each(function() { console.log(" -", $(this).text()); }); } }); ``` or with raw JavaScript source ```js // Print all of the news items on Hacker News var jsdom = require("jsdom"); var fs = require("fs"); var jquery = fs.readFileSync("./jquery.js", "utf-8"); jsdom.env({ url: "http://news.ycombinator.com/", src: [jquery], done: function (errors, window) { var $ = window.$; console.log("HN Links"); $("td.title:not(:last) a").each(function () { console.log(" -", $(this).text()); }); } }); ``` ### How it works The do-what-I-mean API is used like so: ```js jsdom.env(string, [scripts], [config], callback); ``` - `string`: may be a URL, file name, or HTML fragment - `scripts`: a string or array of strings, containing file names or URLs that will be inserted as ` ``` For more details, see the discussion in [#640](https://github.com/tmpvar/jsdom/issues/640), especially [@matthewkastor](https://github.com/matthewkastor)'s [insightful comment](https://github.com/tmpvar/jsdom/issues/640#issuecomment-22216965). ### On running scripts and being safe By default, `jsdom.env` will not process and run external JavaScript, since our sandbox is not foolproof. That is, code running inside the DOM's `