Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 67 lines (43 sloc) 1.953 kb
e1abc48 Elijah Insua added some metadata
authored
1 # jsdom
2
3235f39 Elijah Insua
authored
3 CommonJS implementation of the DOM intended to be platform independent and as minimal/light as possible while completely adhering to the w3c DOM specifications.
4
5 Currently Implemented and w3c Compliant:
6
7 - DOM Level 1 (html/svg/xml)
8 - Browser (BOM) Augmentation (getElementsByClassName, getElementById, etc..)
9
e1abc48 Elijah Insua added some metadata
authored
10
0326b04 Elijah Insua
authored
11 **Note**: Running the tests now requires [mjsunit.runner][]
edfe278 Elijah Insua
authored
12
78518a4 Elijah Insua updated readme to include plan
authored
13 see: [testlog][] for w3 test compliance
03a6f07 Elijah Insua formatting
authored
14
78518a4 Elijah Insua updated readme to include plan
authored
15 see: [plan][] for roadmap and thoughts about this project
70fb7ec Elijah Insua updated readme
authored
16
dccaea1 ulteriorlife actually added link to website in the readme.md
ulteriorlife authored
17 see: [project site][] for additional information
18
5a14da4 ulteriorlife added link to website in the readme.md
ulteriorlife authored
19 [project site]: http://www.jsdom.org
edfe278 Elijah Insua
authored
20 [mjsunit.runner]: http://github.com/tmpvar/mjsunit.runner
fa2e6c2 Elijah Insua
authored
21 [testlog]: http://github.com/tmpvar/jsdom/blob/master/test/testlog.txt
edfe278 Elijah Insua
authored
22 [plan]: http://github.com/tmpvar/jsdom/blob/master/PLAN.md
2351e18 Elijah Insua
authored
23
24
25 # Examples
26
0df8ca5 Elijah Insua updated readme with some important updates
authored
27 ## Creating a document-less window
28
8e0528b Elijah Insua
authored
29 var jsdom = require("jsdom"),
33797d9 Elijah Insua update to jsdom.createWindow(), docs, and a version bump
authored
30 window = jsdom.createWindow();
f25097f Elijah Insua
authored
31
33797d9 Elijah Insua update to jsdom.createWindow(), docs, and a version bump
authored
32 console.log(window.document);
33 // output: undefined
f25097f Elijah Insua
authored
34
33797d9 Elijah Insua update to jsdom.createWindow(), docs, and a version bump
authored
35 ## Creating a document
36 var jsdom = require("jsdom"),
37 doc = new (jsdom.dom.level1.core.Document)();
38 console.log(doc.nodeName);
39 // outputs: #document
0df8ca5 Elijah Insua updated readme with some important updates
authored
40
33797d9 Elijah Insua update to jsdom.createWindow(), docs, and a version bump
authored
41 ## Creating a browser-like BOM/DOM/Window
0df8ca5 Elijah Insua updated readme with some important updates
authored
42
a60bb1c Elijah Insua
authored
43 var jsdom = require("jsdom"),
33797d9 Elijah Insua update to jsdom.createWindow(), docs, and a version bump
authored
44 window = jsdom.createWindow(
45 "<html><head></head><body>hello world</body></html>"
46 );
0df8ca5 Elijah Insua updated readme with some important updates
authored
47
a60bb1c Elijah Insua
authored
48 console.log(window.document.innerHTML);
49 // output: '<html><head></head><body>hello world</body></html>'
0df8ca5 Elijah Insua updated readme with some important updates
authored
50
a60bb1c Elijah Insua
authored
51 console.log(window.innerWidth)
52 // output: 1024
0df8ca5 Elijah Insua updated readme with some important updates
authored
53
a60bb1c Elijah Insua
authored
54 console.log(typeof window.document.getElementsByClassName);
55 // outputs: function
0df8ca5 Elijah Insua updated readme with some important updates
authored
56
2351e18 Elijah Insua
authored
57 ## jQuery
a60bb1c Elijah Insua
authored
58
59 var sys = require("sys"),
60 jsdom = require(__dirname + "/../../lib/jsdom"),
61 window = jsdom.jsdom().createWindow();
2351e18 Elijah Insua
authored
62
a60bb1c Elijah Insua
authored
63 jsdom.jQueryify(window, __dirname + "/jquery.js", function() {
64 window.jQuery('body').append("&lt;div class='testing'&gt;Hello World, It works!&lt;/div&gt;");
65 sys.puts(window.jQuery(".testing").text());
66 });
Something went wrong with that request. Please try again.