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