Added explicit module names to the new unit tests.
[jquery.git] / test / unit / manipulation.js
1 module("manipulation");
2
3 test("text()", function() {
4         expect(1);
5         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
6         equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
7 });
8
9 test("wrap(String|Element)", function() {
10         expect(10);
11         var defaultText = 'Try them out:'
12         var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
13         equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
14         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
15
16         reset();
17         var defaultText = 'Try them out:'
18         var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
19         ok( result.is('ol'), 'Check for element wrapping' );
20         equals( result.text(), defaultText, 'Check for element wrapping' );
21
22         reset();
23         jQuery('#check1').click(function() {
24                 var checkbox = this;
25                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
26                 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
27                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
28         }).click();
29
30         // using contents will get comments regular, text, and comment nodes
31         var j = jQuery("#nonnodes").contents();
32         j.wrap("<i></i>");
33         equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
34         equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
35
36         // Try wrapping a disconnected node
37         j = jQuery("<label/>").wrap("<li/>");
38         equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
39         equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
40 });
41
42 test("wrapAll(String|Element)", function() {
43         expect(8);
44         var prev = jQuery("#firstp")[0].previousSibling;
45         var p = jQuery("#firstp,#first")[0].parentNode;
46         var result = jQuery('#firstp,#first').wrapAll('<div class="red"><div id="tmp"></div></div>');
47         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
48         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
49         ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
50         equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
51         equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
52
53         reset();
54         var prev = jQuery("#firstp")[0].previousSibling;
55         var p = jQuery("#first")[0].parentNode;
56         var result = jQuery('#firstp,#first').wrapAll(document.getElementById('empty'));
57         equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
58         equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
59         equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
60 });
61
62 test("wrapInner(String|Element)", function() {
63         expect(6);
64         var num = jQuery("#first").children().length;
65         var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
66         equals( jQuery("#first").children().length, 1, "Only one child" );
67         ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
68         equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
69
70         reset();
71         var num = jQuery("#first").children().length;
72         var result = jQuery('#first').wrapInner(document.getElementById('empty'));
73         equals( jQuery("#first").children().length, 1, "Only one child" );
74         ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
75         equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
76 });
77
78 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
79         expect(21);
80         var defaultText = 'Try them out:'
81         var result = jQuery('#first').append('<b>buga</b>');
82         equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
83         equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
84
85         reset();
86         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
87         jQuery('#sap').append(document.getElementById('first'));
88         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
89
90         reset();
91         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
92         jQuery('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
93         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
94
95         reset();
96         expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
97         jQuery('#sap').append(jQuery("#first, #yahoo"));
98         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
99
100         reset();
101         jQuery("#sap").append( 5 );
102         ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
103
104         reset();
105         jQuery("#sap").append( " text with spaces " );
106         ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
107
108         reset();
109         ok( jQuery("#sap").append([]), "Check for appending an empty array." );
110         ok( jQuery("#sap").append(""), "Check for appending an empty string." );
111         ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
112
113         reset();
114         jQuery("#sap").append(document.getElementById('form'));
115         equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
116
117         reset();
118         var pass = true;
119         try {
120                 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
121         } catch(e) {
122                 pass = false;
123         }
124
125         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
126
127         reset();
128         jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
129         t( 'Append legend', '#legend', ['legend'] );
130
131         reset();
132         jQuery('#select1').append('<OPTION>Test</OPTION>');
133         equals( jQuery('#select1 option:last').text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
134
135         jQuery('#table').append('<colgroup></colgroup>');
136         ok( jQuery('#table colgroup').length, "Append colgroup" );
137
138         jQuery('#table colgroup').append('<col/>');
139         ok( jQuery('#table colgroup col').length, "Append col" );
140
141         reset();
142         jQuery('#table').append('<caption></caption>');
143         ok( jQuery('#table caption').length, "Append caption" );
144
145         reset();
146         jQuery('form:last')
147                 .append('<select id="appendSelect1"></select>')
148                 .append('<select id="appendSelect2"><option>Test</option></select>');
149
150         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
151
152         // using contents will get comments regular, text, and comment nodes
153         var j = jQuery("#nonnodes").contents();
154         var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
155         equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
156         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
157         d.contents().appendTo("#nonnodes");
158         d.remove();
159         ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
160 });
161
162 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
163         expect(12);
164         var defaultText = 'Try them out:'
165         jQuery('<b>buga</b>').appendTo('#first');
166         equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
167         equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
168
169         reset();
170         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
171         jQuery(document.getElementById('first')).appendTo('#sap');
172         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
173
174         reset();
175         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
176         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
177         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
178
179         reset();
180         ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
181
182         reset();
183         expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
184         jQuery("#first, #yahoo").appendTo('#sap');
185         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
186
187         reset();
188         jQuery('#select1').appendTo('#foo');
189         t( 'Append select', '#foo select', ['select1'] );
190
191         reset();
192         var div = jQuery("<div/>").click(function(){
193                 ok(true, "Running a cloned click.");
194         });
195         div.appendTo("#main, #moretests");
196
197         jQuery("#main div:last").click();
198         jQuery("#moretests div:last").click();
199
200         reset();
201         var div = jQuery("<div/>").appendTo("#main, #moretests");
202
203         equals( div.length, 2, "appendTo returns the inserted elements" );
204         
205         div.addClass("test");
206
207         ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
208         ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
209
210         reset();
211 });
212
213 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
214         expect(5);
215         var defaultText = 'Try them out:'
216         var result = jQuery('#first').prepend('<b>buga</b>');
217         equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
218         equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
219
220         reset();
221         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
222         jQuery('#sap').prepend(document.getElementById('first'));
223         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
224
225         reset();
226         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
227         jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
228         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
229
230         reset();
231         expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
232         jQuery('#sap').prepend(jQuery("#first, #yahoo"));
233         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
234 });
235
236 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
237         expect(6);
238         var defaultText = 'Try them out:'
239         jQuery('<b>buga</b>').prependTo('#first');
240         equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
241         equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
242
243         reset();
244         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
245         jQuery(document.getElementById('first')).prependTo('#sap');
246         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
247
248         reset();
249         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
250         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
251         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
252
253         reset();
254         expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
255         jQuery("#first, #yahoo").prependTo('#sap');
256         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
257
258         reset();
259         jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
260         jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
261
262         t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
263 });
264
265 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
266         expect(4);
267         var expected = 'This is a normal link: bugaYahoo';
268         jQuery('#yahoo').before('<b>buga</b>');
269         equals( expected, jQuery('#en').text(), 'Insert String before' );
270
271         reset();
272         expected = "This is a normal link: Try them out:Yahoo";
273         jQuery('#yahoo').before(document.getElementById('first'));
274         equals( expected, jQuery('#en').text(), "Insert element before" );
275
276         reset();
277         expected = "This is a normal link: Try them out:diveintomarkYahoo";
278         jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
279         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
280
281         reset();
282         expected = "This is a normal link: diveintomarkTry them out:Yahoo";
283         jQuery('#yahoo').before(jQuery("#first, #mark"));
284         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
285 });
286
287 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
288         expect(4);
289         var expected = 'This is a normal link: bugaYahoo';
290         jQuery('<b>buga</b>').insertBefore('#yahoo');
291         equals( expected, jQuery('#en').text(), 'Insert String before' );
292
293         reset();
294         expected = "This is a normal link: Try them out:Yahoo";
295         jQuery(document.getElementById('first')).insertBefore('#yahoo');
296         equals( expected, jQuery('#en').text(), "Insert element before" );
297
298         reset();
299         expected = "This is a normal link: Try them out:diveintomarkYahoo";
300         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
301         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
302
303         reset();
304         expected = "This is a normal link: diveintomarkTry them out:Yahoo";
305         jQuery("#first, #mark").insertBefore('#yahoo');
306         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
307 });
308
309 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
310         expect(4);
311         var expected = 'This is a normal link: Yahoobuga';
312         jQuery('#yahoo').after('<b>buga</b>');
313         equals( expected, jQuery('#en').text(), 'Insert String after' );
314
315         reset();
316         expected = "This is a normal link: YahooTry them out:";
317         jQuery('#yahoo').after(document.getElementById('first'));
318         equals( expected, jQuery('#en').text(), "Insert element after" );
319
320         reset();
321         expected = "This is a normal link: YahooTry them out:diveintomark";
322         jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
323         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
324
325         reset();
326         expected = "This is a normal link: YahoodiveintomarkTry them out:";
327         jQuery('#yahoo').after(jQuery("#first, #mark"));
328         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
329 });
330
331 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
332         expect(4);
333         var expected = 'This is a normal link: Yahoobuga';
334         jQuery('<b>buga</b>').insertAfter('#yahoo');
335         equals( expected, jQuery('#en').text(), 'Insert String after' );
336
337         reset();
338         expected = "This is a normal link: YahooTry them out:";
339         jQuery(document.getElementById('first')).insertAfter('#yahoo');
340         equals( expected, jQuery('#en').text(), "Insert element after" );
341
342         reset();
343         expected = "This is a normal link: YahooTry them out:diveintomark";
344         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
345         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
346
347         reset();
348         expected = "This is a normal link: YahoodiveintomarkTry them out:";
349         jQuery("#first, #mark").insertAfter('#yahoo');
350         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
351 });
352
353 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
354         expect(10);
355         jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
356         ok( jQuery("#replace")[0], 'Replace element with string' );
357         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
358
359         reset();
360         jQuery('#yahoo').replaceWith(document.getElementById('first'));
361         ok( jQuery("#first")[0], 'Replace element with element' );
362         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
363
364         reset();
365         jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
366         ok( jQuery("#first")[0], 'Replace element with array of elements' );
367         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
368         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
369
370         reset();
371         jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
372         ok( jQuery("#first")[0], 'Replace element with set of elements' );
373         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
374         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
375 });
376
377 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
378         expect(10);
379         jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
380         ok( jQuery("#replace")[0], 'Replace element with string' );
381         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
382
383         reset();
384         jQuery(document.getElementById('first')).replaceAll("#yahoo");
385         ok( jQuery("#first")[0], 'Replace element with element' );
386         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
387
388         reset();
389         jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
390         ok( jQuery("#first")[0], 'Replace element with array of elements' );
391         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
392         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
393
394         reset();
395         jQuery("#first, #mark").replaceAll("#yahoo");
396         ok( jQuery("#first")[0], 'Replace element with set of elements' );
397         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
398         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
399 });
400
401 test("clone()", function() {
402         expect(28);
403         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
404         var clone = jQuery('#yahoo').clone();
405         equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
406         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
407
408         var cloneTags = [
409                 "<table/>", "<tr/>", "<td/>", "<div/>",
410                 "<button/>", "<ul/>", "<ol/>", "<li/>",
411                 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
412                 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
413         ];
414         for (var i = 0; i < cloneTags.length; i++) {
415                 var j = jQuery(cloneTags[i]);
416                 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
417         }
418
419         // using contents will get comments regular, text, and comment nodes
420         var cl = jQuery("#nonnodes").contents().clone();
421         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
422
423         var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
424                 ok( true, "Bound event still exists." );
425         });
426
427         div = div.clone(true).clone(true);
428         equals( div.length, 1, "One element cloned" );
429         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
430         div.trigger("click");
431
432         div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
433         div.find("table").click(function(){
434                 ok( true, "Bound event still exists." );
435         });
436
437         div = div.clone(true);
438         equals( div.length, 1, "One element cloned" );
439         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
440         div.find("table:last").trigger("click");
441
442         div = jQuery("<div/>").html('<object height="355" width="425">  <param name="movie" value="http://www.youtube.com/v/JikaHBDoV3k&amp;hl=en">  <param name="wmode" value="transparent"> </object>');
443
444         div = div.clone(true);
445         equals( div.length, 1, "One element cloned" );
446         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
447 });
448
449 if (!isLocal) {
450 test("clone() on XML nodes", function() {
451         expect(2);
452         stop();
453         jQuery.get("data/dashboard.xml", function (xml) {
454                 var root = jQuery(xml.documentElement).clone();
455                 var origTab = jQuery("tab", xml).eq(0);
456                 var cloneTab = jQuery("tab", root).eq(0);
457                 origTab.text("origval");
458                 cloneTab.text("cloneval");
459                 equals(origTab.text(), "origval", "Check original XML node was correctly set");
460                 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
461                 start();
462         });
463 });
464 }
465
466 test("val()", function() {
467         expect(8);
468
469         equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
470         // ticket #1714 this caused a JS error in IE
471         equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
472         ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
473         
474         equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
475
476         isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
477
478         equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
479         
480         equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
481         
482         equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
483         
484 });
485
486 test("val(String/Number)", function() {
487         expect(6);
488         document.getElementById('text1').value = "bla";
489         equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
490         
491         jQuery("#text1").val('test');
492         equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
493         
494         jQuery("#text1").val(67);
495         equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
496
497         jQuery("#select1").val("3");
498         equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
499
500         jQuery("#select1").val(2);
501         equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
502
503         // using contents will get comments regular, text, and comment nodes
504         var j = jQuery("#nonnodes").contents();
505         j.val("asdf");
506         equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
507         j.removeAttr("value");
508 });
509
510 test("html(String)", function() {
511         expect(17);
512         
513         jQuery.scriptorder = 0;
514         
515         var div = jQuery("#main > div");
516         div.html("<b>test</b>");
517         var pass = true;
518         for ( var i = 0; i < div.size(); i++ ) {
519                 if ( div.get(i).childNodes.length != 1 ) pass = false;
520         }
521         ok( pass, "Set HTML" );
522
523         reset();
524         // using contents will get comments regular, text, and comment nodes
525         var j = jQuery("#nonnodes").contents();
526         j.html("<b>bold</b>");
527
528         // this is needed, or the expando added by jQuery unique will yield a different html
529         j.find('b').removeData();
530         equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
531
532         jQuery("#main").html("<select/>");
533         jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
534         equals( jQuery("#main select").val(), "O2", "Selected option correct" );
535
536         var $div = jQuery('<div />');
537         equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
538         equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
539
540         reset();
541
542         jQuery("#main").html('<script type="something/else">ok( false, "Non-script evaluated." );</script><script type="text/javascript">ok( true, "text/javascript is evaluated." );</script><script>ok( true, "No type is evaluated." );</script><div><script type="text/javascript">ok( true, "Inner text/javascript is evaluated." );</script><script>ok( true, "Inner No type is evaluated." );</script><script type="something/else">ok( false, "Non-script evaluated." );</script></div>');
543
544         stop();
545
546         jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
547
548         jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
549
550         // 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
551         jQuery("#main").html("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
552
553         setTimeout( start, 100 );
554 });
555
556 test("text(String)", function() {
557         expect(4);
558         equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
559
560         // using contents will get comments regular, text, and comment nodes
561         var j = jQuery("#nonnodes").contents();
562         j.text("hi!");
563         equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
564         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
565         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
566 });
567
568 test("remove()", function() {
569         expect(7);
570         jQuery("#ap").children().remove();
571         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
572         equals( jQuery("#ap").children().length, 0, "Check remove" );
573
574         reset();
575         jQuery("#ap").children().remove("a");
576         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
577         equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
578
579         jQuery("#ap").children().remove("a, code");
580         equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
581
582         // using contents will get comments regular, text, and comment nodes
583         equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
584         jQuery("#nonnodes").contents().remove();
585         equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
586 });
587
588 test("empty()", function() {
589         expect(3);
590         equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
591         equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
592
593         // using contents will get comments regular, text, and comment nodes
594         var j = jQuery("#nonnodes").contents();
595         j.empty();
596         equals( j.html(), "", "Check node,textnode,comment empty works" );
597 });
598