Skip to content

Commit

Permalink
fixed the example to config object
Browse files Browse the repository at this point in the history
  • Loading branch information
karunasagark committed May 15, 2011
1 parent c107b78 commit 76c7415
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions README.md
Expand Up @@ -16,41 +16,50 @@ or

Bootstrapping a DOM is generally a difficult process involving many error prone steps. We didn't want jsdom to fall into the same trap and that is why a new method, `jsdom.env()`, has been added in jsdom 0.2.0 which should make everyone's lives easier.

with URL

// Count all of the links from the nodejs build page
var jsdom = require("jsdom");

jsdom.env("http://nodejs.org/dist/", [
'http://code.jquery.com/jquery-1.5.min.js'
], function(errors, window) {
console.log("there have been", window.$("a").length, "nodejs releases!");
});
jsdom.env("http://nodejs.org/dist/",
[
'http://code.jquery.com/jquery-1.5.min.js'
],
function(errors, window) {
console.log("there have been", window.$("a").length, "nodejs releases!");
});

or with raw html

// Run some jQuery on a html fragment
var jsdom = require('jsdom');

jsdom.env('<p><a class="the-link" href="http://jsdom.org>JSDOM\'s Homepage</a></p>', [
'http://code.jquery.com/jquery-1.5.min.js'
], function(errors, window) {
console.log("contents of a.the-link:", window.$("a.the-link").text());
});
jsdom.env('<p><a class="the-link" href="http://jsdom.org>JSDOM\'s Homepage</a></p>',
[
'http://code.jquery.com/jquery-1.5.min.js'
],
function(errors, window) {
console.log("contents of a.the-link:", window.$("a.the-link").text());
});

or with a configuration object

// Print all of the news items on hackernews
var jsdom = require('jsdom');

jsdom.env('http://news.ycombinator.com/', [
'http://code.jquery.com/jquery-1.5.min.js'
], function(errors, window) {
var $ = window.$;

console.log('HN Links');
$('td.title:not(:last) a').each(function() {
console.log(' -', $(this).text());
});
});
jsdom.env({
html: 'http://news.ycombinator.com/',
scripts: [
'http://code.jquery.com/jquery-1.5.min.js'
],
done: function(errors, window) {
var $ = window.$;
console.log('HN Links');
$('td.title:not(:last) a').each(function() {
console.log(' -', $(this).text());
});
}
});


### How it works
Expand Down

0 comments on commit 76c7415

Please sign in to comment.