1 module("manipulation");
3 var bareObj = function(value) { return value; };
4 var functionReturningObj = function(value) { return (function() { return value; }); };
6 test("text()", function() {
8 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
9 equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
12 test("wrap(String|Element)", function() {
14 var defaultText = 'Try them out:'
15 var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
16 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
17 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
20 var defaultText = 'Try them out:'
21 var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
22 ok( result.is('ol'), 'Check for element wrapping' );
23 equals( result.text(), defaultText, 'Check for element wrapping' );
26 jQuery('#check1').click(function() {
28 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
29 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
30 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
33 // using contents will get comments regular, text, and comment nodes
34 var j = jQuery("#nonnodes").contents();
36 equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
37 equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
39 // Try wrapping a disconnected node
40 j = jQuery("<label/>").wrap("<li/>");
41 equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
42 equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
45 test("wrapAll(String|Element)", function() {
47 var prev = jQuery("#firstp")[0].previousSibling;
48 var p = jQuery("#firstp,#first")[0].parentNode;
49 var result = jQuery('#firstp,#first').wrapAll('<div class="red"><div id="tmp"></div></div>');
50 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
51 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
52 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
53 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
54 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
57 var prev = jQuery("#firstp")[0].previousSibling;
58 var p = jQuery("#first")[0].parentNode;
59 var result = jQuery('#firstp,#first').wrapAll(document.getElementById('empty'));
60 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
61 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
62 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
65 var testWrapInner = function(val) {
67 var num = jQuery("#first").children().length;
68 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
69 equals( jQuery("#first").children().length, 1, "Only one child" );
70 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
71 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
74 var num = jQuery("#first").children().length;
75 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
76 equals( jQuery("#first").children().length, 1, "Only one child" );
77 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
78 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
81 test("wrapInner(String|Element)", function() {
82 testWrapInner(bareObj);
85 /* test("wrapInner(Function)", function() {
86 testWrapInner(functionReturningObj)
89 var testAppend = function(valueObj) {
91 var defaultText = 'Try them out:'
92 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
93 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
94 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
97 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
98 jQuery('#sap').append(valueObj(document.getElementById('first')));
99 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
102 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
103 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
104 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
107 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
108 jQuery('#sap').append(valueObj(jQuery("#first, #yahoo")));
109 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
112 jQuery("#sap").append(valueObj( 5 ));
113 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
116 jQuery("#sap").append(valueObj( " text with spaces " ));
117 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
120 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
121 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
122 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
125 jQuery("#sap").append(valueObj( document.getElementById('form') ));
126 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
131 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append(valueObj( "<div>test</div>" ));
136 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
139 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
140 t( 'Append legend', '#legend', ['legend'] );
143 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
144 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
146 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
147 ok( jQuery('#table colgroup').length, "Append colgroup" );
149 jQuery('#table colgroup').append(valueObj( '<col/>' ));
150 ok( jQuery('#table colgroup col').length, "Append col" );
153 jQuery('#table').append(valueObj( '<caption></caption>' ));
154 ok( jQuery('#table caption').length, "Append caption" );
158 .append(valueObj( '<select id="appendSelect1"></select>' ))
159 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
161 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
163 // using contents will get comments regular, text, and comment nodes
164 var j = jQuery("#nonnodes").contents();
165 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
166 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
167 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
168 d.contents().appendTo("#nonnodes");
170 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
173 test("append(String|Element|Array<Element>|jQuery)", function() {
177 test("append(Function)", function() {
178 testAppend(functionReturningObj);
181 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
183 var defaultText = 'Try them out:'
184 jQuery('<b>buga</b>').appendTo('#first');
185 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
186 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
189 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
190 jQuery(document.getElementById('first')).appendTo('#sap');
191 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
194 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
195 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
196 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
199 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
202 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
203 jQuery("#first, #yahoo").appendTo('#sap');
204 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
207 jQuery('#select1').appendTo('#foo');
208 t( 'Append select', '#foo select', ['select1'] );
211 var div = jQuery("<div/>").click(function(){
212 ok(true, "Running a cloned click.");
214 div.appendTo("#main, #moretests");
216 jQuery("#main div:last").click();
217 jQuery("#moretests div:last").click();
220 var div = jQuery("<div/>").appendTo("#main, #moretests");
222 equals( div.length, 2, "appendTo returns the inserted elements" );
224 div.addClass("test");
226 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
227 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
232 var testPrepend = function(val) {
234 var defaultText = 'Try them out:'
235 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
236 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
237 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
240 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
241 jQuery('#sap').prepend(val( document.getElementById('first') ));
242 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
245 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
246 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
247 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
250 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
251 jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
252 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
255 test("prepend(String|Element|Array<Element>|jQuery)", function() {
256 testPrepend(bareObj);
259 test("prepend(Function)", function() {
260 testPrepend(functionReturningObj);
263 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
265 var defaultText = 'Try them out:'
266 jQuery('<b>buga</b>').prependTo('#first');
267 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
268 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
271 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
272 jQuery(document.getElementById('first')).prependTo('#sap');
273 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
276 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
277 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
278 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
281 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
282 jQuery("#first, #yahoo").prependTo('#sap');
283 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
286 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
287 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
289 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
292 var testBefore = function(val) {
294 var expected = 'This is a normal link: bugaYahoo';
295 jQuery('#yahoo').before(val( '<b>buga</b>' ));
296 equals( expected, jQuery('#en').text(), 'Insert String before' );
299 expected = "This is a normal link: Try them out:Yahoo";
300 jQuery('#yahoo').before(val( document.getElementById('first') ));
301 equals( expected, jQuery('#en').text(), "Insert element before" );
304 expected = "This is a normal link: Try them out:diveintomarkYahoo";
305 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
306 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
309 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
310 jQuery('#yahoo').before(val( jQuery("#first, #mark") ));
311 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
314 test("before(String|Element|Array<Element>|jQuery)", function() {
318 test("before(Function)", function() {
319 testBefore(functionReturningObj);
322 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
324 var expected = 'This is a normal link: bugaYahoo';
325 jQuery('<b>buga</b>').insertBefore('#yahoo');
326 equals( expected, jQuery('#en').text(), 'Insert String before' );
329 expected = "This is a normal link: Try them out:Yahoo";
330 jQuery(document.getElementById('first')).insertBefore('#yahoo');
331 equals( expected, jQuery('#en').text(), "Insert element before" );
334 expected = "This is a normal link: Try them out:diveintomarkYahoo";
335 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
336 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
339 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
340 jQuery("#first, #mark").insertBefore('#yahoo');
341 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
344 var testAfter = function(val) {
346 var expected = 'This is a normal link: Yahoobuga';
347 jQuery('#yahoo').after(val( '<b>buga</b>' ));
348 equals( expected, jQuery('#en').text(), 'Insert String after' );
351 expected = "This is a normal link: YahooTry them out:";
352 jQuery('#yahoo').after(val( document.getElementById('first') ));
353 equals( expected, jQuery('#en').text(), "Insert element after" );
356 expected = "This is a normal link: YahooTry them out:diveintomark";
357 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
358 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
361 expected = "This is a normal link: YahoodiveintomarkTry them out:";
362 jQuery('#yahoo').after(val( jQuery("#first, #mark") ));
363 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
366 test("after(String|Element|Array<Element>|jQuery)", function() {
370 test("after(Function)", function() {
371 testAfter(functionReturningObj);
374 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
376 var expected = 'This is a normal link: Yahoobuga';
377 jQuery('<b>buga</b>').insertAfter('#yahoo');
378 equals( expected, jQuery('#en').text(), 'Insert String after' );
381 expected = "This is a normal link: YahooTry them out:";
382 jQuery(document.getElementById('first')).insertAfter('#yahoo');
383 equals( expected, jQuery('#en').text(), "Insert element after" );
386 expected = "This is a normal link: YahooTry them out:diveintomark";
387 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
388 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
391 expected = "This is a normal link: YahoodiveintomarkTry them out:";
392 jQuery("#first, #mark").insertAfter('#yahoo');
393 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
396 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
398 jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
399 ok( jQuery("#replace")[0], 'Replace element with string' );
400 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
403 jQuery('#yahoo').replaceWith(document.getElementById('first'));
404 ok( jQuery("#first")[0], 'Replace element with element' );
405 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
408 jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
409 ok( jQuery("#first")[0], 'Replace element with array of elements' );
410 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
411 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
414 jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
415 ok( jQuery("#first")[0], 'Replace element with set of elements' );
416 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
417 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
420 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
422 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
423 ok( jQuery("#replace")[0], 'Replace element with string' );
424 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
427 jQuery(document.getElementById('first')).replaceAll("#yahoo");
428 ok( jQuery("#first")[0], 'Replace element with element' );
429 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
432 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
433 ok( jQuery("#first")[0], 'Replace element with array of elements' );
434 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
435 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
438 jQuery("#first, #mark").replaceAll("#yahoo");
439 ok( jQuery("#first")[0], 'Replace element with set of elements' );
440 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
441 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
444 test("clone()", function() {
446 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
447 var clone = jQuery('#yahoo').clone();
448 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
449 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
452 "<table/>", "<tr/>", "<td/>", "<div/>",
453 "<button/>", "<ul/>", "<ol/>", "<li/>",
454 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
455 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
457 for (var i = 0; i < cloneTags.length; i++) {
458 var j = jQuery(cloneTags[i]);
459 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
462 // using contents will get comments regular, text, and comment nodes
463 var cl = jQuery("#nonnodes").contents().clone();
464 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
466 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
467 ok( true, "Bound event still exists." );
470 div = div.clone(true).clone(true);
471 equals( div.length, 1, "One element cloned" );
472 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
473 div.trigger("click");
475 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
476 div.find("table").click(function(){
477 ok( true, "Bound event still exists." );
480 div = div.clone(true);
481 equals( div.length, 1, "One element cloned" );
482 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
483 div.find("table:last").trigger("click");
485 div = jQuery("<div/>").html('<object height="355" width="425"> <param name="movie" value="http://www.youtube.com/v/JikaHBDoV3k&hl=en"> <param name="wmode" value="transparent"> </object>');
487 div = div.clone(true);
488 equals( div.length, 1, "One element cloned" );
489 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
493 test("clone() on XML nodes", function() {
496 jQuery.get("data/dashboard.xml", function (xml) {
497 var root = jQuery(xml.documentElement).clone();
498 var origTab = jQuery("tab", xml).eq(0);
499 var cloneTab = jQuery("tab", root).eq(0);
500 origTab.text("origval");
501 cloneTab.text("cloneval");
502 equals(origTab.text(), "origval", "Check original XML node was correctly set");
503 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
509 test("val()", function() {
512 document.getElementById('text1').value = "bla";
513 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
517 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
518 // ticket #1714 this caused a JS error in IE
519 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
520 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
522 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
524 isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
526 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
528 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
530 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
534 var testVal = function(valueObj) {
537 jQuery("#text1").val(valueObj( 'test' ));
538 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
540 jQuery("#text1").val(valueObj( 67 ));
541 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
543 jQuery("#select1").val(valueObj( "3" ));
544 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
546 jQuery("#select1").val(valueObj( 2 ));
547 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
549 // using contents will get comments regular, text, and comment nodes
550 var j = jQuery("#nonnodes").contents();
551 j.val(valueObj( "asdf" ));
552 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
553 j.removeAttr("value");
556 test("val(String/Number)", function() {
560 test("val(Function)", function() {
561 testVal(functionReturningObj);
564 var testHtml = function(valueObj) {
569 jQuery.scriptorder = 0;
571 var div = jQuery("#main > div");
572 div.html(valueObj("<b>test</b>"));
574 for ( var i = 0; i < div.size(); i++ ) {
575 if ( div.get(i).childNodes.length != 1 ) pass = false;
577 ok( pass, "Set HTML" );
579 window.debug = false;
582 // using contents will get comments regular, text, and comment nodes
583 var j = jQuery("#nonnodes").contents();
584 j.html(valueObj("<b>bold</b>"));
586 // this is needed, or the expando added by jQuery unique will yield a different html
587 j.find('b').removeData();
588 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
590 jQuery("#main").html(valueObj("<select/>"));
591 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
592 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
594 var $div = jQuery('<div />');
595 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
596 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
600 jQuery("#main").html(valueObj('<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>'));
604 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>'));
606 jQuery("#main").html(valueObj('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'));
608 // 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
609 jQuery("#main").html(valueObj("<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>"));
611 setTimeout( start, 100 );
614 test("html(String)", function() {
618 test("html(Function)", function() {
619 testHtml(functionReturningObj);
622 var testText = function(valueObj) {
624 equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
626 // using contents will get comments regular, text, and comment nodes
627 var j = jQuery("#nonnodes").contents();
629 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
630 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
631 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
634 test("text(String)", function() {
638 test("text(Function)", function() {
639 testText(functionReturningObj);
642 test("remove()", function() {
644 jQuery("#ap").children().remove();
645 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
646 equals( jQuery("#ap").children().length, 0, "Check remove" );
649 jQuery("#ap").children().remove("a");
650 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
651 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
653 jQuery("#ap").children().remove("a, code");
654 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
656 // using contents will get comments regular, text, and comment nodes
657 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
658 jQuery("#nonnodes").contents().remove();
659 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
662 test("empty()", function() {
664 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
665 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
667 // using contents will get comments regular, text, and comment nodes
668 var j = jQuery("#nonnodes").contents();
670 equals( j.html(), "", "Check node,textnode,comment empty works" );