Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 78 lines (51 sloc) 2.294 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
87665f3 Elijah Insua made jsdom.jsdom() accept html, do browserAugmentation, etc.. updated te...
authored
43 var jsdom = require("./lib/jsdom").jsdom,
44 window = jsdom("<html><head></head><body>hello world</body></html>").createWindow();
0df8ca5 Elijah Insua updated readme with some important updates
authored
45
a60bb1c Elijah Insua
authored
46 console.log(window.document.innerHTML);
47 // output: '<html><head></head><body>hello world</body></html>'
0df8ca5 Elijah Insua updated readme with some important updates
authored
48
a60bb1c Elijah Insua
authored
49 console.log(window.innerWidth)
50 // output: 1024
0df8ca5 Elijah Insua updated readme with some important updates
authored
51
a60bb1c Elijah Insua
authored
52 console.log(typeof window.document.getElementsByClassName);
53 // outputs: function
0df8ca5 Elijah Insua updated readme with some important updates
authored
54
30575d5 Elijah Insua fixed examples, and a bug in createWindow()
authored
55 ## Load arbitrary scripts
56 var jsdom = require("jsdom").jsdom,
57 window = jsdom().createWindow(),
58 script = window.document.createElement("script");
59
60 script.src = 'http://code.jquery.com/jquery-1.4.2.js';
61
62 script.onload = function() {
63 if (this.readyState === 'complete') {
64 console.log(window.jQuery.fn.jquery);
65 // outputs: 1.4.2
66 }
67 };
a60bb1c Elijah Insua
authored
68
30575d5 Elijah Insua fixed examples, and a bug in createWindow()
authored
69 ## jQueryify
70
71 var jsdom = require("jsdom"),
a60bb1c Elijah Insua
authored
72 window = jsdom.jsdom().createWindow();
30575d5 Elijah Insua fixed examples, and a bug in createWindow()
authored
73
74 jsdom.jQueryify(window, "http://code.jquery.com/jquery-1.4.2.min.js" , function() {
75 window.jQuery('body').append(<div class='testing'>Hello World, It works</div>");
76 console.log(window.jQuery(".testing").text());
a60bb1c Elijah Insua
authored
77 });
Something went wrong with that request. Please try again.