3ca1e9510c2cfa96d6948ba406b037030a710b2a
[jquery.git] / test / unit / core.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
5         ok( Array.prototype.push, "Array.push()" );
6         ok( Function.prototype.apply, "Function.apply()" );
7         ok( document.getElementById, "getElementById" );
8         ok( document.getElementsByTagName, "getElementsByTagName" );
9         ok( RegExp, "RegExp" );
10         ok( jQuery, "jQuery" );
11         ok( $, "$()" );
12 });
13
14 test("$()", function() {
15         expect(4);
16         
17         var main = $("#main");
18         isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19         
20 /*
21         // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22         // what the expected behavior should even be. FF returns "\n" for the text node
23         // make sure this is handled
24         var crlfContainer = $('<p>\r\n</p>');
25         var x = crlfContainer.contents().get(0).nodeValue;
26         equals( x, what???, "Check for \\r and \\n in jQuery()" );
27 */
28         
29         /* // Disabled until we add this functionality in
30         var pass = true;
31         try {
32                 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
33         } catch(e){
34                 pass = false;
35         }
36         ok( pass, "$('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
37
38         var code = $("<code/>");
39         equals( code.length, 1, "Correct number of elements generated for code" );
40         var img = $("<img/>");
41         equals( img.length, 1, "Correct number of elements generated for img" );
42         var div = $("<div/><hr/><code/><b/>");
43         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
44 });
45
46 test("browser", function() {
47         expect(13);
48         var browsers = {
49                 //Internet Explorer
50                 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
51                 "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0",
52                 /** Failing #1876
53                  * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0",
54                  */
55                 //Browsers with Gecko engine
56                 //Mozilla
57                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
58                 //Firefox
59                 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3",
60                 //Netscape
61                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
62                 //Flock
63                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11",
64                 //Opera browser
65                 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
66                 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
67                 "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
68                 //WebKit engine
69                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
70                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
71                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
72                 //Other user agent string
73                 "Other browser's user agent 1.0":null
74         };
75         for (var i in browsers) {
76                 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
77                 version = v ? v[1] : null;
78                 equals( version, browsers[i], "Checking UA string" );
79         }
80 });
81
82 test("noConflict", function() {
83         expect(6);
84         
85         var old = jQuery;
86         var newjQuery = jQuery.noConflict();
87
88         ok( newjQuery == old, "noConflict returned the jQuery object" );
89         ok( jQuery == old, "Make sure jQuery wasn't touched." );
90         ok( $ == "$", "Make sure $ was reverted." );
91
92         jQuery = $ = old;
93
94         newjQuery = jQuery.noConflict(true);
95
96         ok( newjQuery == old, "noConflict returned the jQuery object" );
97         ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
98         ok( $ == "$", "Make sure $ was reverted." );
99
100         jQuery = $ = old;
101 });
102
103 test("isFunction", function() {
104         expect(21);
105
106         // Make sure that false values return false
107         ok( !jQuery.isFunction(), "No Value" );
108         ok( !jQuery.isFunction( null ), "null Value" );
109         ok( !jQuery.isFunction( undefined ), "undefined Value" );
110         ok( !jQuery.isFunction( "" ), "Empty String Value" );
111         ok( !jQuery.isFunction( 0 ), "0 Value" );
112
113         // Check built-ins
114         // Safari uses "(Internal Function)"
115         ok( jQuery.isFunction(String), "String Function" );
116         ok( jQuery.isFunction(Array), "Array Function" );
117         ok( jQuery.isFunction(Object), "Object Function" );
118         ok( jQuery.isFunction(Function), "Function Function" );
119
120         // When stringified, this could be misinterpreted
121         var mystr = "function";
122         ok( !jQuery.isFunction(mystr), "Function String" );
123
124         // When stringified, this could be misinterpreted
125         var myarr = [ "function" ];
126         ok( !jQuery.isFunction(myarr), "Function Array" );
127
128         // When stringified, this could be misinterpreted
129         var myfunction = { "function": "test" };
130         ok( !jQuery.isFunction(myfunction), "Function Object" );
131
132         // Make sure normal functions still work
133         var fn = function(){};
134         ok( jQuery.isFunction(fn), "Normal Function" );
135
136         var obj = document.createElement("object");
137
138         // Firefox says this is a function
139         ok( !jQuery.isFunction(obj), "Object Element" );
140
141         // IE says this is an object
142         ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
143
144         var nodes = document.body.childNodes;
145
146         // Safari says this is a function
147         ok( !jQuery.isFunction(nodes), "childNodes Property" );
148
149         var first = document.body.firstChild;
150         
151         // Normal elements are reported ok everywhere
152         ok( !jQuery.isFunction(first), "A normal DOM Element" );
153
154         var input = document.createElement("input");
155         input.type = "text";
156         document.body.appendChild( input );
157
158         // IE says this is an object
159         ok( jQuery.isFunction(input.focus), "A default function property" );
160
161         document.body.removeChild( input );
162
163         var a = document.createElement("a");
164         a.href = "some-function";
165         document.body.appendChild( a );
166
167         // This serializes with the word 'function' in it
168         ok( !jQuery.isFunction(a), "Anchor Element" );
169
170         document.body.removeChild( a );
171
172         // Recursive function calls have lengths and array-like properties
173         function callme(callback){
174                 function fn(response){
175                         callback(response);
176                 }
177
178                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
179
180                 fn({ some: "data" });
181         };
182
183         callme(function(){
184                 callme(function(){});
185         });
186 });
187
188 var foo = false;
189
190 test("$('html')", function() {
191         expect(6);
192
193         reset();
194         foo = false;
195         var s = $("<script>var foo='test';</script>")[0];
196         ok( s, "Creating a script" );
197         ok( !foo, "Make sure the script wasn't executed prematurely" );
198         $("body").append(s);
199         ok( foo, "Executing a scripts contents in the right context" );
200         
201         reset();
202         ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
203         
204         reset();
205
206         var j = $("<span>hi</span> there <!-- mon ami -->");
207         ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
208
209         ok( !$("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
210 });
211
212 test("$('html', context)", function() {
213         expect(1);
214
215         var $div = $("<div/>");
216         var $span = $("<span/>", $div);
217         equals($span.length, 1, "Verify a span created with a div context works, #1763");
218 });
219
220 if ( !isLocal ) {
221 test("$(selector, xml).text(str) - Loaded via XML document", function() {
222         expect(2);
223         stop();
224         $.get('data/dashboard.xml', function(xml) { 
225                 // tests for #1419 where IE was a problem
226                 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
227                 $("tab:first", xml).text("newtext");
228                 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
229                 start();
230         });
231 });
232 }
233
234 test("length", function() {
235         expect(1);
236         ok( $("p").length == 6, "Get Number of Elements Found" );
237 });
238
239 test("size()", function() {
240         expect(1);
241         ok( $("p").size() == 6, "Get Number of Elements Found" );
242 });
243
244 test("get()", function() {
245         expect(1);
246         isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
247 });
248
249 test("get(Number)", function() {
250         expect(1);
251         ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
252 });
253
254 test("add(String|Element|Array|undefined)", function() {
255         expect(8);
256         isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
257         isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
258         ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
259
260         // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE
261         // use $([]).add(form.elements) instead.
262         //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" );
263         
264         var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
265         ok( x[0].id == "x1", "Check on-the-fly element1" );
266         ok( x[1].id == "x2", "Check on-the-fly element2" );
267         
268         var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
269         ok( x[0].id == "x1", "Check on-the-fly element1" );
270         ok( x[1].id == "x2", "Check on-the-fly element2" );
271         
272         var notDefined;
273         equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." );
274 });
275
276 test("each(Function)", function() {
277         expect(1);
278         var div = $("div");
279         div.each(function(){this.foo = 'zoo';});
280         var pass = true;
281         for ( var i = 0; i < div.size(); i++ ) {
282                 if ( div.get(i).foo != "zoo" ) pass = false;
283         }
284         ok( pass, "Execute a function, Relative" );
285 });
286
287 test("index(Object)", function() {
288         expect(8);
289         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
290         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
291         var inputElements = $('#radio1,#radio2,#check1,#check2');
292         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
293         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
294         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
295         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
296         ok( inputElements.index(window) == -1, "Check for not found index" );
297         ok( inputElements.index(document) == -1, "Check for not found index" );
298 });
299
300 test("attr(String)", function() {
301         expect(20);
302         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
303         ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
304         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
305         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
306         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
307         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
308         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
309         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
310         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
311         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
312         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
313         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
314         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
315         ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
316         ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
317         ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
318         ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
319         ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
320         ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
321         
322         $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
323         ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
324 });
325
326 if ( !isLocal ) {
327         test("attr(String) in XML Files", function() {
328                 expect(2);
329                 stop();
330                 $.get("data/dashboard.xml", function(xml) {
331                         ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
332                         ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
333                         start();
334                 });
335         });
336 }
337
338 test("attr(String, Function)", function() {
339         expect(2);
340         ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
341         ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
342 });
343
344 test("attr(Hash)", function() {
345         expect(1);
346         var pass = true;
347         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
348                 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
349         });
350         ok( pass, "Set Multiple Attributes" );
351 });
352
353 test("attr(String, Object)", function() {
354         expect(17);
355         var div = $("div");
356         div.attr("foo", "bar");
357         var pass = true;
358         for ( var i = 0; i < div.size(); i++ ) {
359                 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
360         }
361         ok( pass, "Set Attribute" );
362
363         ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );    
364         
365         $("#name").attr('name', 'something');
366         ok( $("#name").attr('name') == 'something', 'Set name attribute' );
367         $("#check2").attr('checked', true);
368         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
369         $("#check2").attr('checked', false);
370         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
371         $("#text1").attr('readonly', true);
372         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
373         $("#text1").attr('readonly', false);
374         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
375         $("#name").attr('maxlength', '5');
376         ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
377         $("#name").attr('maxLength', '10');
378         ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
379
380         // for #1070
381         $("#name").attr('someAttr', '0');
382         equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
383         $("#name").attr('someAttr', 0);
384         equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
385         $("#name").attr('someAttr', 1);
386         equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
387
388         // using contents will get comments regular, text, and comment nodes
389         var j = $("#nonnodes").contents();
390
391         j.attr("name", "attrvalue");
392         equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
393         j.removeAttr("name")
394
395         reset();
396
397         var type = $("#check2").attr('type');
398         var thrown = false;
399         try {
400                 $("#check2").attr('type','hidden');
401         } catch(e) {
402                 thrown = true;
403         }
404         ok( thrown, "Exception thrown when trying to change type property" );
405         equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
406
407         var check = document.createElement("input");
408         var thrown = true;
409         try {
410                 $(check).attr('type','checkbox');
411         } catch(e) {
412                 thrown = false;
413         }
414         ok( thrown, "Exception thrown when trying to change type property" );
415         equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
416 });
417
418 if ( !isLocal ) {
419         test("attr(String, Object) - Loaded via XML document", function() {
420                 expect(2);
421                 stop();
422                 $.get('data/dashboard.xml', function(xml) { 
423                         var titles = [];
424                         $('tab', xml).each(function() {
425                                 titles.push($(this).attr('title'));
426                         });
427                         equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
428                         equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
429                         start();
430                 });
431         });
432 }
433
434 test("css(String|Hash)", function() {
435         expect(19);
436         
437         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
438         
439         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
440         $('#foo').css({display: 'none'});
441         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
442         $('#foo').css({display: 'block'});
443         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
444         
445         $('#floatTest').css({styleFloat: 'right'});
446         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
447         $('#floatTest').css({cssFloat: 'left'});
448         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
449         $('#floatTest').css({'float': 'right'});
450         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
451         $('#floatTest').css({'font-size': '30px'});
452         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
453         
454         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
455                 $('#foo').css({opacity: n});
456                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
457                 $('#foo').css({opacity: parseFloat(n)});
458                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
459         });     
460         $('#foo').css({opacity: ''});
461         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
462 });
463
464 test("css(String, Object)", function() {
465         expect(21);
466         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
467         $('#foo').css('display', 'none');
468         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
469         $('#foo').css('display', 'block');
470         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
471         
472         $('#floatTest').css('styleFloat', 'left');
473         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
474         $('#floatTest').css('cssFloat', 'right');
475         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
476         $('#floatTest').css('float', 'left');
477         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
478         $('#floatTest').css('font-size', '20px');
479         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
480         
481         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
482                 $('#foo').css('opacity', n);
483                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
484                 $('#foo').css('opacity', parseFloat(n));
485                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
486         });
487         $('#foo').css('opacity', '');
488         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
489         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
490         if (jQuery.browser.msie) {
491                 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
492         }
493         equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
494
495         // using contents will get comments regular, text, and comment nodes
496         var j = $("#nonnodes").contents();
497         j.css("padding-left", "1px");
498         equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
499
500         // opera sometimes doesn't update 'display' correctly, see #2037
501         $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML
502         equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
503 });
504
505 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
506         expect(4);
507
508         var $checkedtest = $("#checkedtest");
509         // IE6 was clearing "checked" in jQuery.css(elem, "height");
510         jQuery.css($checkedtest[0], "height");
511         ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
512         ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
513         ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
514         ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
515 });
516
517 test("width()", function() {
518         expect(9);
519
520         var $div = $("#nothiddendiv");
521         $div.width(30);
522         equals($div.width(), 30, "Test set to 30 correctly");
523         $div.width(-1); // handle negative numbers by ignoring #1599
524         equals($div.width(), 30, "Test negative width ignored");
525         $div.css("padding", "20px");
526         equals($div.width(), 30, "Test padding specified with pixels");
527         $div.css("border", "2px solid #fff");
528         equals($div.width(), 30, "Test border specified with pixels");
529         $div.css("padding", "2em");
530         equals($div.width(), 30, "Test padding specified with ems");
531         $div.css("border", "1em solid #fff");
532         equals($div.width(), 30, "Test border specified with ems");
533         $div.css("padding", "2%");
534         equals($div.width(), 30, "Test padding specified with percent");
535         $div.hide();
536         equals($div.width(), 30, "Test hidden div");
537         
538         $div.css({ display: "", border: "", padding: "" });
539         
540         $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
541         equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding");
542         $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
543 });
544
545 test("height()", function() {
546         expect(8);
547
548         var $div = $("#nothiddendiv");
549         $div.height(30);
550         equals($div.height(), 30, "Test set to 30 correctly");
551         $div.height(-1); // handle negative numbers by ignoring #1599
552         equals($div.height(), 30, "Test negative height ignored");
553         $div.css("padding", "20px");
554         equals($div.height(), 30, "Test padding specified with pixels");
555         $div.css("border", "2px solid #fff");
556         equals($div.height(), 30, "Test border specified with pixels");
557         $div.css("padding", "2em");
558         equals($div.height(), 30, "Test padding specified with ems");
559         $div.css("border", "1em solid #fff");
560         equals($div.height(), 30, "Test border specified with ems");
561         $div.css("padding", "2%");
562         equals($div.height(), 30, "Test padding specified with percent");
563         $div.hide();
564         equals($div.height(), 30, "Test hidden div");
565         
566         $div.css({ display: "", border: "", padding: "", height: "1px" });
567 });
568
569 test("text()", function() {
570         expect(1);
571         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
572         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
573 });
574
575 test("wrap(String|Element)", function() {
576         expect(8);
577         var defaultText = 'Try them out:'
578         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
579         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
580         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
581
582         reset();
583         var defaultText = 'Try them out:'
584         var result = $('#first').wrap(document.getElementById('empty')).parent();
585         ok( result.is('ol'), 'Check for element wrapping' );
586         ok( result.text() == defaultText, 'Check for element wrapping' );
587         
588         reset();
589         $('#check1').click(function() {         
590                 var checkbox = this;            
591                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
592                 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
593                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
594         }).click();
595
596         // using contents will get comments regular, text, and comment nodes
597         var j = $("#nonnodes").contents();
598         j.wrap("<i></i>");
599         equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
600         equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
601 });
602
603 test("wrapAll(String|Element)", function() {
604         expect(8);
605         var prev = $("#first")[0].previousSibling;
606         var p = $("#first")[0].parentNode;
607         var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
608         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
609         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
610         ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
611         equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
612         equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
613
614         reset();
615         var prev = $("#first")[0].previousSibling;
616         var p = $("#first")[0].parentNode;
617         var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
618         equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
619         equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
620         equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
621 });
622
623 test("wrapInner(String|Element)", function() {
624         expect(6);
625         var num = $("#first").children().length;
626         var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
627         equals( $("#first").children().length, 1, "Only one child" );
628         ok( $("#first").children().is(".red"), "Verify Right Element" );
629         equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
630
631         reset();
632         var num = $("#first").children().length;
633         var result = $('#first').wrapInner(document.getElementById('empty'));
634         equals( $("#first").children().length, 1, "Only one child" );
635         ok( $("#first").children().is("#empty"), "Verify Right Element" );
636         equals( $("#first").children().children().length, num, "Verify Elements Intact" );
637 });
638
639 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
640         expect(21);
641         var defaultText = 'Try them out:'
642         var result = $('#first').append('<b>buga</b>');
643         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
644         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
645         
646         reset();
647         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
648         $('#sap').append(document.getElementById('first'));
649         ok( expected == $('#sap').text(), "Check for appending of element" );
650         
651         reset();
652         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
653         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
654         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
655         
656         reset();
657         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
658         $('#sap').append($("#first, #yahoo"));
659         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
660
661         reset();
662         $("#sap").append( 5 );
663         ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
664
665         reset();
666         $("#sap").append( " text with spaces " );
667         ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
668
669         reset();
670         ok( $("#sap").append([]), "Check for appending an empty array." );
671         ok( $("#sap").append(""), "Check for appending an empty string." );
672         ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
673         
674         reset();
675         $("#sap").append(document.getElementById('form'));
676         ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
677
678         reset();
679         var pass = true;
680         try {
681                 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
682         } catch(e) {
683                 pass = false;
684         }
685
686         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
687         
688         reset();
689         $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
690         t( 'Append legend', '#legend', ['legend'] );
691         
692         reset();
693         $('#select1').append('<OPTION>Test</OPTION>');
694         ok( $('#select1 option:last').text() == "Test", "Appending &lt;OPTION&gt; (all caps)" );
695         
696         $('#table').append('<colgroup></colgroup>');
697         ok( $('#table colgroup').length, "Append colgroup" );
698         
699         $('#table colgroup').append('<col/>');
700         ok( $('#table colgroup col').length, "Append col" );
701         
702         reset();
703         $('#table').append('<caption></caption>');
704         ok( $('#table caption').length, "Append caption" );
705
706         reset();
707         $('form:last')
708                 .append('<select id="appendSelect1"></select>')
709                 .append('<select id="appendSelect2"><option>Test</option></select>');
710         
711         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
712
713         // using contents will get comments regular, text, and comment nodes
714         var j = $("#nonnodes").contents();
715         var d = $("<div/>").appendTo("#nonnodes").append(j);
716         equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
717         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
718         d.contents().appendTo("#nonnodes");
719         d.remove();
720         ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
721 });
722
723 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
724         expect(6);
725         var defaultText = 'Try them out:'
726         $('<b>buga</b>').appendTo('#first');
727         ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
728         ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
729         
730         reset();
731         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
732         $(document.getElementById('first')).appendTo('#sap');
733         ok( expected == $('#sap').text(), "Check for appending of element" );
734         
735         reset();
736         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
737         $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
738         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
739         
740         reset();
741         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
742         $("#first, #yahoo").appendTo('#sap');
743         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
744         
745         reset();
746         $('#select1').appendTo('#foo');
747         t( 'Append select', '#foo select', ['select1'] );
748 });
749
750 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
751         expect(5);
752         var defaultText = 'Try them out:'
753         var result = $('#first').prepend('<b>buga</b>');
754         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
755         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
756         
757         reset();
758         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
759         $('#sap').prepend(document.getElementById('first'));
760         ok( expected == $('#sap').text(), "Check for prepending of element" );
761
762         reset();
763         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
764         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
765         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
766         
767         reset();
768         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
769         $('#sap').prepend($("#first, #yahoo"));
770         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
771 });
772
773 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
774         expect(6);
775         var defaultText = 'Try them out:'
776         $('<b>buga</b>').prependTo('#first');
777         ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
778         ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
779         
780         reset();
781         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
782         $(document.getElementById('first')).prependTo('#sap');
783         ok( expected == $('#sap').text(), "Check for prepending of element" );
784
785         reset();
786         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
787         $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
788         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
789         
790         reset();
791         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
792         $("#yahoo, #first").prependTo('#sap');
793         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
794         
795         reset();
796         $('<select id="prependSelect1"></select>').prependTo('form:last');
797         $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
798         
799         t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
800 });
801
802 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
803         expect(4);
804         var expected = 'This is a normal link: bugaYahoo';
805         $('#yahoo').before('<b>buga</b>');
806         ok( expected == $('#en').text(), 'Insert String before' );
807         
808         reset();
809         expected = "This is a normal link: Try them out:Yahoo";
810         $('#yahoo').before(document.getElementById('first'));
811         ok( expected == $('#en').text(), "Insert element before" );
812         
813         reset();
814         expected = "This is a normal link: Try them out:diveintomarkYahoo";
815         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
816         ok( expected == $('#en').text(), "Insert array of elements before" );
817         
818         reset();
819         expected = "This is a normal link: Try them out:diveintomarkYahoo";
820         $('#yahoo').before($("#first, #mark"));
821         ok( expected == $('#en').text(), "Insert jQuery before" );
822 });
823
824 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
825         expect(4);
826         var expected = 'This is a normal link: bugaYahoo';
827         $('<b>buga</b>').insertBefore('#yahoo');
828         ok( expected == $('#en').text(), 'Insert String before' );
829         
830         reset();
831         expected = "This is a normal link: Try them out:Yahoo";
832         $(document.getElementById('first')).insertBefore('#yahoo');
833         ok( expected == $('#en').text(), "Insert element before" );
834         
835         reset();
836         expected = "This is a normal link: Try them out:diveintomarkYahoo";
837         $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
838         ok( expected == $('#en').text(), "Insert array of elements before" );
839         
840         reset();
841         expected = "This is a normal link: Try them out:diveintomarkYahoo";
842         $("#first, #mark").insertBefore('#yahoo');
843         ok( expected == $('#en').text(), "Insert jQuery before" );
844 });
845
846 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
847         expect(4);
848         var expected = 'This is a normal link: Yahoobuga';
849         $('#yahoo').after('<b>buga</b>');
850         ok( expected == $('#en').text(), 'Insert String after' );
851         
852         reset();
853         expected = "This is a normal link: YahooTry them out:";
854         $('#yahoo').after(document.getElementById('first'));
855         ok( expected == $('#en').text(), "Insert element after" );
856
857         reset();
858         expected = "This is a normal link: YahooTry them out:diveintomark";
859         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
860         ok( expected == $('#en').text(), "Insert array of elements after" );
861         
862         reset();
863         expected = "This is a normal link: YahooTry them out:diveintomark";
864         $('#yahoo').after($("#first, #mark"));
865         ok( expected == $('#en').text(), "Insert jQuery after" );
866 });
867
868 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
869         expect(4);
870         var expected = 'This is a normal link: Yahoobuga';
871         $('<b>buga</b>').insertAfter('#yahoo');
872         ok( expected == $('#en').text(), 'Insert String after' );
873         
874         reset();
875         expected = "This is a normal link: YahooTry them out:";
876         $(document.getElementById('first')).insertAfter('#yahoo');
877         ok( expected == $('#en').text(), "Insert element after" );
878
879         reset();
880         expected = "This is a normal link: YahooTry them out:diveintomark";
881         $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
882         ok( expected == $('#en').text(), "Insert array of elements after" );
883         
884         reset();
885         expected = "This is a normal link: YahooTry them out:diveintomark";
886         $("#mark, #first").insertAfter('#yahoo');
887         ok( expected == $('#en').text(), "Insert jQuery after" );
888 });
889
890 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
891         expect(10);
892         $('#yahoo').replaceWith('<b id="replace">buga</b>');
893         ok( $("#replace")[0], 'Replace element with string' );
894         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
895         
896         reset();
897         $('#yahoo').replaceWith(document.getElementById('first'));
898         ok( $("#first")[0], 'Replace element with element' );
899         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
900
901         reset();
902         $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
903         ok( $("#first")[0], 'Replace element with array of elements' );
904         ok( $("#mark")[0], 'Replace element with array of elements' );
905         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
906         
907         reset();
908         $('#yahoo').replaceWith($("#first, #mark"));
909         ok( $("#first")[0], 'Replace element with set of elements' );
910         ok( $("#mark")[0], 'Replace element with set of elements' );
911         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
912 });
913
914 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
915         expect(10);
916         $('<b id="replace">buga</b>').replaceAll("#yahoo");
917         ok( $("#replace")[0], 'Replace element with string' );
918         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
919         
920         reset();
921         $(document.getElementById('first')).replaceAll("#yahoo");
922         ok( $("#first")[0], 'Replace element with element' );
923         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
924
925         reset();
926         $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
927         ok( $("#first")[0], 'Replace element with array of elements' );
928         ok( $("#mark")[0], 'Replace element with array of elements' );
929         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
930         
931         reset();
932         $("#first, #mark").replaceAll("#yahoo");
933         ok( $("#first")[0], 'Replace element with set of elements' );
934         ok( $("#mark")[0], 'Replace element with set of elements' );
935         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
936 });
937
938 test("end()", function() {
939         expect(3);
940         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
941         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
942         
943         var x = $('#yahoo');
944         x.parent();
945         ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
946 });
947
948 test("find(String)", function() {
949         expect(2);
950         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
951
952         // using contents will get comments regular, text, and comment nodes
953         var j = $("#nonnodes").contents();
954         equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
955 });
956
957 test("clone()", function() {
958         expect(20);
959         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
960         var clone = $('#yahoo').clone();
961         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
962         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
963
964         var cloneTags = [ 
965                 "<table/>", "<tr/>", "<td/>", "<div/>", 
966                 "<button/>", "<ul/>", "<ol/>", "<li/>",
967                 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
968                 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
969         ];
970         for (var i = 0; i < cloneTags.length; i++) {
971                 var j = $(cloneTags[i]);
972                 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
973         }
974
975         // using contents will get comments regular, text, and comment nodes
976         var cl = $("#nonnodes").contents().clone();
977         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
978 });
979
980 if (!isLocal) {
981 test("clone() on XML nodes", function() {
982         expect(2);
983         stop();
984         $.get("data/dashboard.xml", function (xml) {
985                 var root = $(xml.documentElement).clone();
986                 $("tab:first", xml).text("origval");
987                 $("tab:first", root).text("cloneval");
988                 equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
989                 equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
990                 start();
991         });
992 });
993 }
994
995 test("is(String)", function() {
996         expect(26);
997         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
998         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
999         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1000         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1001         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1002         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1003         ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1004         ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1005         ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1006         ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1007         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1008         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1009         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1010         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1011         ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
1012         ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
1013         ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1014         ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1015         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
1016         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
1017         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
1018         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1019         
1020         // test is() with comma-seperated expressions
1021         ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1022         ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1023         ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1024         ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1025 });
1026
1027 test("$.extend(Object, Object)", function() {
1028         expect(17);
1029
1030         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1031                 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1032                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1033                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
1034                 deep1 = { foo: { bar: true } },
1035                 deep1copy = { foo: { bar: true } },
1036                 deep2 = { foo: { baz: true }, foo2: document },
1037                 deep2copy = { foo: { baz: true }, foo2: document },
1038                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
1039
1040         jQuery.extend(settings, options);
1041         isObj( settings, merged, "Check if extended: settings must be extended" );
1042         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1043
1044         jQuery.extend(settings, null, options);
1045         isObj( settings, merged, "Check if extended: settings must be extended" );
1046         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1047
1048         jQuery.extend(true, deep1, deep2);
1049         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
1050         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
1051         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
1052
1053         var target = {};
1054         var recursive = { foo:target, bar:5 };
1055         jQuery.extend(true, target, recursive);
1056         isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1057
1058         var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1059         ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
1060
1061         var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1062         ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
1063
1064         var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1065         ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
1066
1067         var obj = { foo:null };
1068         jQuery.extend(true, obj, { foo:"notnull" } );
1069         equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1070
1071         function func() {}
1072         jQuery.extend(func, { key: "value" } );
1073         equals( func.key, "value", "Verify a function can be extended" );
1074
1075         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1076                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1077                 options1 = { xnumber2: 1, xstring2: "x" },
1078                 options1Copy = { xnumber2: 1, xstring2: "x" },
1079                 options2 = { xstring2: "xx", xxx: "newstringx" },
1080                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
1081                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1082
1083         var settings = jQuery.extend({}, defaults, options1, options2);
1084         isObj( settings, merged2, "Check if extended: settings must be extended" );
1085         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1086         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1087         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1088 });
1089
1090 test("val()", function() {
1091         expect(4);
1092         ok( $("#text1").val() == "Test", "Check for value of input element" );
1093         ok( !$("#text1").val() == "", "Check for value of input element" );
1094         // ticket #1714 this caused a JS error in IE
1095         ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
1096         ok( $([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
1097 });
1098
1099 test("val(String)", function() {
1100         expect(4);
1101         document.getElementById('text1').value = "bla";
1102         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
1103         $("#text1").val('test');
1104         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
1105         
1106         $("#select1").val("3");
1107         ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
1108
1109         // using contents will get comments regular, text, and comment nodes
1110         var j = $("#nonnodes").contents();
1111         j.val("asdf");
1112         equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
1113         j.removeAttr("value");
1114 });
1115
1116 var scriptorder = 0;
1117
1118 test("html(String)", function() {
1119         expect(11);
1120         var div = $("#main > div");
1121         div.html("<b>test</b>");
1122         var pass = true;
1123         for ( var i = 0; i < div.size(); i++ ) {
1124                 if ( div.get(i).childNodes.length != 1 ) pass = false;
1125         }
1126         ok( pass, "Set HTML" );
1127
1128         reset();
1129         // using contents will get comments regular, text, and comment nodes
1130         var j = $("#nonnodes").contents();
1131         j.html("<b>bold</b>");
1132         equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1133
1134         $("#main").html("<select/>");
1135         $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
1136         equals( $("#main select").val(), "O2", "Selected option correct" );
1137
1138         stop();
1139
1140         $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
1141
1142         $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
1143
1144         // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
1145         $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script (nested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script (unnested) is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
1146
1147         setTimeout( start, 100 );
1148 });
1149
1150 test("filter()", function() {
1151         expect(6);
1152         isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
1153         isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
1154         isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
1155         isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
1156
1157         // using contents will get comments regular, text, and comment nodes
1158         var j = $("#nonnodes").contents();
1159         equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
1160         equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
1161 });
1162
1163 test("not()", function() {
1164         expect(8);
1165         ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
1166         ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" );
1167         isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
1168         isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
1169         isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
1170         ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" );
1171         isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
1172         
1173         var selects = $("#form select");
1174         isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
1175 });
1176
1177 test("andSelf()", function() {
1178         expect(4);
1179         isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
1180         isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1181         isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
1182         isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1183 });
1184
1185 test("siblings([String])", function() {
1186         expect(5);
1187         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1188         isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
1189         isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1190         isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1191         isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1192 });
1193
1194 test("children([String])", function() {
1195         expect(3);
1196         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1197         isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1198         isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1199 });
1200
1201 test("parent([String])", function() {
1202         expect(5);
1203         ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
1204         ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
1205         ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
1206         ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
1207         isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1208 });
1209         
1210 test("parents([String])", function() {
1211         expect(5);
1212         ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
1213         ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
1214         ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
1215         isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1216         isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1217 });
1218
1219 test("next([String])", function() {
1220         expect(4);
1221         ok( $("#ap").next()[0].id == "foo", "Simple next check" );
1222         ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
1223         ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
1224         ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
1225 });
1226         
1227 test("prev([String])", function() {
1228         expect(4);
1229         ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
1230         ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
1231         ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
1232         ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
1233 });
1234
1235 test("show()", function() {
1236         expect(15);
1237         var pass = true, div = $("div");
1238         div.show().each(function(){
1239                 if ( this.style.display == "none" ) pass = false;
1240         });
1241         ok( pass, "Show" );
1242         
1243         $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
1244         var test = {
1245                 "div"      : "block",
1246                 "p"        : "block",
1247                 "a"        : "inline",
1248                 "code"     : "inline",
1249                 "pre"      : "block",
1250                 "span"     : "inline",
1251                 "table"    : $.browser.msie ? "block" : "table",
1252                 "thead"    : $.browser.msie ? "block" : "table-header-group",
1253                 "tbody"    : $.browser.msie ? "block" : "table-row-group",
1254                 "tr"       : $.browser.msie ? "block" : "table-row",
1255                 "th"       : $.browser.msie ? "block" : "table-cell",
1256                 "td"       : $.browser.msie ? "block" : "table-cell",
1257                 "ul"       : "block",
1258                 "li"       : $.browser.msie ? "block" : "list-item"
1259         };
1260         
1261         $.each(test, function(selector, expected) {
1262                 var elem = $(selector, "#show-tests").show();
1263                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
1264         });
1265 });
1266
1267 test("addClass(String)", function() {
1268         expect(2);
1269         var div = $("div");
1270         div.addClass("test");
1271         var pass = true;
1272         for ( var i = 0; i < div.size(); i++ ) {
1273          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1274         }
1275         ok( pass, "Add Class" );
1276
1277         // using contents will get regular, text, and comment nodes
1278         var j = $("#nonnodes").contents();
1279         j.addClass("asdf");
1280         ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1281 });
1282
1283 test("removeClass(String) - simple", function() {
1284         expect(4);
1285         var div = $("div").addClass("test").removeClass("test"),
1286                 pass = true;
1287         for ( var i = 0; i < div.size(); i++ ) {
1288                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
1289         }
1290         ok( pass, "Remove Class" );
1291         
1292         reset();
1293         var div = $("div").addClass("test").addClass("foo").addClass("bar");
1294         div.removeClass("test").removeClass("bar").removeClass("foo");
1295         var pass = true;
1296         for ( var i = 0; i < div.size(); i++ ) {
1297          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1298         }
1299         ok( pass, "Remove multiple classes" );
1300         
1301         reset();
1302         var div = $("div:eq(0)").addClass("test").removeClass("");
1303         ok( div.is('.test'), "Empty string passed to removeClass" );
1304         
1305         // using contents will get regular, text, and comment nodes
1306         var j = $("#nonnodes").contents();
1307         j.removeClass("asdf");
1308         ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1309 });
1310
1311 test("toggleClass(String)", function() {
1312         expect(3);
1313         var e = $("#firstp");
1314         ok( !e.is(".test"), "Assert class not present" );
1315         e.toggleClass("test");
1316         ok( e.is(".test"), "Assert class present" ); 
1317         e.toggleClass("test");
1318         ok( !e.is(".test"), "Assert class not present" );
1319 });
1320
1321 test("removeAttr(String", function() {
1322         expect(1);
1323         ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1324 });
1325
1326 test("text(String)", function() {
1327         expect(4);
1328         ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1329
1330         // using contents will get comments regular, text, and comment nodes
1331         var j = $("#nonnodes").contents();
1332         j.text("hi!");
1333         equals( $(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
1334         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
1335         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
1336 });
1337
1338 test("$.each(Object,Function)", function() {
1339         expect(12);
1340         $.each( [0,1,2], function(i, n){
1341                 ok( i == n, "Check array iteration" );
1342         });
1343         
1344         $.each( [5,6,7], function(i, n){
1345                 ok( i == n - 5, "Check array iteration" );
1346         });
1347          
1348         $.each( { name: "name", lang: "lang" }, function(i, n){
1349                 ok( i == n, "Check object iteration" );
1350         });
1351
1352         var total = 0;
1353         jQuery.each([1,2,3], function(i,v){ total += v; });
1354         ok( total == 6, "Looping over an array" );
1355         total = 0;
1356         jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
1357         ok( total == 3, "Looping over an array, with break" );
1358         total = 0;
1359         jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
1360         ok( total == 6, "Looping over an object" );
1361         total = 0;
1362         jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
1363         ok( total == 3, "Looping over an object, with break" );
1364 });
1365
1366 test("$.prop", function() {
1367         expect(2);
1368         var handle = function() { return this.id };
1369         ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1370         ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1371 });
1372
1373 test("$.className", function() {
1374         expect(6);
1375         var x = $("<p>Hi</p>")[0];
1376         var c = $.className;
1377         c.add(x, "hi");
1378         ok( x.className == "hi", "Check single added class" );
1379         c.add(x, "foo bar");
1380         ok( x.className == "hi foo bar", "Check more added classes" );
1381         c.remove(x);
1382         ok( x.className == "", "Remove all classes" );
1383         c.add(x, "hi foo bar");
1384         c.remove(x, "foo");
1385         ok( x.className == "hi bar", "Check removal of one class" );
1386         ok( c.has(x, "hi"), "Check has1" );
1387         ok( c.has(x, "bar"), "Check has2" );
1388 });
1389
1390 test("$.data", function() {
1391         expect(3);
1392         var div = $("#foo")[0];
1393         ok( jQuery.data(div, "test") == undefined, "Check for no data exists" );
1394         jQuery.data(div, "test", "success");
1395         ok( jQuery.data(div, "test") == "success", "Check for added data" );
1396         jQuery.data(div, "test", "overwritten");
1397         ok( jQuery.data(div, "test") == "overwritten", "Check for overwritten data" );
1398 });
1399
1400 test(".data()", function() {
1401         expect(11);
1402         var div = $("#foo");
1403         ok( div.data("test") == undefined, "Check for no data exists" );
1404         div.data("test", "success");
1405         ok( div.data("test") == "success", "Check for added data" );
1406         div.data("test", "overwritten");
1407         ok( div.data("test") == "overwritten", "Check for overwritten data" );
1408
1409         var hits = {test:0};
1410
1411         div
1412                 .bind("setData",function(e,key,value){ hits[key] += value; })
1413                 .bind("setData.foo",function(e,key,value){ hits[key] += value; })
1414
1415         div.data("test.foo", 2);
1416         ok( div.data("test") == "overwritten", "Check for original data" );
1417         ok( div.data("test.foo") == 2, "Check for namespaced data" );
1418         ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" );
1419         ok( hits.test == 2, "Check triggered functions" );
1420
1421         hits.test = 0;
1422
1423         div.data("test", 1);
1424         ok( div.data("test") == 1, "Check for original data" );
1425         ok( div.data("test.foo") == 2, "Check for namespaced data" );
1426         ok( div.data("test.bar") == 1, "Check for unmatched namespace" );
1427         ok( hits.test == 1, "Check triggered functions" );
1428 });
1429
1430 test("$.removeData", function() {
1431         expect(1);
1432         var div = $("#foo")[0];
1433         jQuery.data(div, "test", "testing");
1434         jQuery.removeData(div, "test");
1435         ok( jQuery.data(div, "test") == undefined, "Check removal of data" );
1436 });
1437
1438 test(".removeData()", function() {
1439         expect(6);
1440         var div = $("#foo");
1441         div.data("test", "testing");
1442         div.removeData("test");
1443         ok( div.data("test") == undefined, "Check removal of data" );
1444
1445         div.data("test", "testing");
1446         div.data("test.foo", "testing2");
1447         div.removeData("test.bar");
1448         ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
1449         ok( div.data("test") == "testing", "Make sure data is intact" );
1450
1451         div.removeData("test");
1452         ok( div.data("test.foo") == "testing2", "Make sure data is intact" );
1453         ok( div.data("test") == undefined, "Make sure data is intact" );
1454
1455         div.removeData("test.foo");
1456         ok( div.data("test.foo") == undefined, "Make sure data is intact" );
1457 });
1458
1459 test("remove()", function() {
1460         expect(6);
1461         $("#ap").children().remove();
1462         ok( $("#ap").text().length > 10, "Check text is not removed" );
1463         ok( $("#ap").children().length == 0, "Check remove" );
1464         
1465         reset();
1466         $("#ap").children().remove("a");
1467         ok( $("#ap").text().length > 10, "Check text is not removed" );
1468         ok( $("#ap").children().length == 1, "Check filtered remove" );
1469
1470         // using contents will get comments regular, text, and comment nodes
1471         equals( $("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1472         $("#nonnodes").contents().remove();
1473         equals( $("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1474 });
1475
1476 test("empty()", function() {
1477         expect(3);
1478         ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1479         ok( $("#ap").children().length == 4, "Check elements are not removed" );
1480
1481         // using contents will get comments regular, text, and comment nodes
1482         var j = $("#nonnodes").contents();
1483         j.empty();
1484         equals( j.html(), "", "Check node,textnode,comment empty works" );
1485 });
1486
1487 test("slice()", function() {
1488         expect(5);
1489         isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1490         isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1491         isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1492         isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1493
1494         isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1495 });
1496
1497 test("map()", function() {
1498         expect(2);
1499
1500         isSet(
1501                 $("#ap").map(function(){
1502                         return $(this).find("a").get();
1503                 }),
1504                 q("google", "groups", "anchor1", "mark"),
1505                 "Array Map"
1506         );
1507
1508         isSet(
1509                 $("#ap > a").map(function(){
1510                         return this.parentNode;
1511                 }),
1512                 q("ap","ap","ap"),
1513                 "Single Map"
1514         );
1515 });
1516
1517 test("contents()", function() {
1518         expect(12);
1519         equals( $("#ap").contents().length, 9, "Check element contents" );
1520         ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1521         var ibody = $("#loadediframe").contents()[0].body;
1522         ok( ibody, "Check existance of IFrame body" );
1523
1524         equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1525
1526         $(ibody).append("<div>init text</div>");
1527         equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1528
1529         equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1530
1531         $("div:last", ibody).text("div text");
1532         equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1533
1534         $("div:last", ibody).remove();
1535         equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1536
1537         equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1538
1539         $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1540         $("table", ibody).remove();
1541         equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1542
1543         // using contents will get comments regular, text, and comment nodes
1544         var c = $("#nonnodes").contents().contents();
1545         equals( c.length, 1, "Check node,textnode,comment contents is just one" );
1546         equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
1547 });