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 var testWrap = function(val) {
14 var defaultText = 'Try them out:'
15 var result = jQuery('#first').wrap(val( '<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(val( 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(val( '<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();
35 j.wrap(val( "<i></i>" ));
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(val( "<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("wrap(String|Element)", function() {
49 test("wrap(Function)", function() {
50 testWrap(functionReturningObj);
53 var testWrapAll = function(val) {
55 var prev = jQuery("#firstp")[0].previousSibling;
56 var p = jQuery("#firstp,#first")[0].parentNode;
58 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
59 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
60 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
61 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
62 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
63 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
66 var prev = jQuery("#firstp")[0].previousSibling;
67 var p = jQuery("#first")[0].parentNode;
68 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
69 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
70 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
71 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
74 test("wrapAll(String|Element)", function() {
78 // TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
79 // test("wrapAll(Function)", function() {
80 // testWrapAll(functionReturningObj);
83 var testWrapInner = function(val) {
85 var num = jQuery("#first").children().length;
86 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
87 equals( jQuery("#first").children().length, 1, "Only one child" );
88 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
89 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
92 var num = jQuery("#first").children().length;
93 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
94 equals( jQuery("#first").children().length, 1, "Only one child" );
95 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
96 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
99 test("wrapInner(String|Element)", function() {
100 testWrapInner(bareObj);
103 // TODO: wrapInner uses wrapAll -- get wrapAll working with Function
104 // test("wrapInner(Function)", function() {
105 // testWrapInner(functionReturningObj)
108 var testAppend = function(valueObj) {
110 var defaultText = 'Try them out:'
111 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
112 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
113 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
116 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
117 jQuery('#sap').append(valueObj(document.getElementById('first')));
118 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
121 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
122 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
123 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
126 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
127 jQuery('#sap').append(valueObj(jQuery("#first, #yahoo")));
128 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
131 jQuery("#sap").append(valueObj( 5 ));
132 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
135 jQuery("#sap").append(valueObj( " text with spaces " ));
136 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
139 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
140 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
141 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
144 jQuery("#sap").append(valueObj( document.getElementById('form') ));
145 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
150 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append(valueObj( "<div>test</div>" ));
155 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
158 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
159 t( 'Append legend', '#legend', ['legend'] );
162 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
163 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
165 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
166 ok( jQuery('#table colgroup').length, "Append colgroup" );
168 jQuery('#table colgroup').append(valueObj( '<col/>' ));
169 ok( jQuery('#table colgroup col').length, "Append col" );
172 jQuery('#table').append(valueObj( '<caption></caption>' ));
173 ok( jQuery('#table caption').length, "Append caption" );
177 .append(valueObj( '<select id="appendSelect1"></select>' ))
178 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
180 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
182 // using contents will get comments regular, text, and comment nodes
183 var j = jQuery("#nonnodes").contents();
184 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
185 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
186 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
187 d.contents().appendTo("#nonnodes");
189 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
192 test("append(String|Element|Array<Element>|jQuery)", function() {
196 test("append(Function)", function() {
197 testAppend(functionReturningObj);
200 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
202 var defaultText = 'Try them out:'
203 jQuery('<b>buga</b>').appendTo('#first');
204 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
205 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
208 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
209 jQuery(document.getElementById('first')).appendTo('#sap');
210 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
213 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
214 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
215 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
218 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
221 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
222 jQuery("#first, #yahoo").appendTo('#sap');
223 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
226 jQuery('#select1').appendTo('#foo');
227 t( 'Append select', '#foo select', ['select1'] );
230 var div = jQuery("<div/>").click(function(){
231 ok(true, "Running a cloned click.");
233 div.appendTo("#main, #moretests");
235 jQuery("#main div:last").click();
236 jQuery("#moretests div:last").click();
239 var div = jQuery("<div/>").appendTo("#main, #moretests");
241 equals( div.length, 2, "appendTo returns the inserted elements" );
243 div.addClass("test");
245 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
246 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
251 var testPrepend = function(val) {
253 var defaultText = 'Try them out:'
254 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
255 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
256 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
259 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
260 jQuery('#sap').prepend(val( document.getElementById('first') ));
261 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
264 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
265 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
266 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
269 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
270 jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
271 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
274 test("prepend(String|Element|Array<Element>|jQuery)", function() {
275 testPrepend(bareObj);
278 test("prepend(Function)", function() {
279 testPrepend(functionReturningObj);
282 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
284 var defaultText = 'Try them out:'
285 jQuery('<b>buga</b>').prependTo('#first');
286 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
287 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
290 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
291 jQuery(document.getElementById('first')).prependTo('#sap');
292 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
295 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
296 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
297 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
300 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
301 jQuery("#first, #yahoo").prependTo('#sap');
302 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
305 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
306 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
308 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
311 var testBefore = function(val) {
313 var expected = 'This is a normal link: bugaYahoo';
314 jQuery('#yahoo').before(val( '<b>buga</b>' ));
315 equals( expected, jQuery('#en').text(), 'Insert String before' );
318 expected = "This is a normal link: Try them out:Yahoo";
319 jQuery('#yahoo').before(val( document.getElementById('first') ));
320 equals( expected, jQuery('#en').text(), "Insert element before" );
323 expected = "This is a normal link: Try them out:diveintomarkYahoo";
324 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
325 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
328 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
329 jQuery('#yahoo').before(val( jQuery("#first, #mark") ));
330 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
333 test("before(String|Element|Array<Element>|jQuery)", function() {
337 test("before(Function)", function() {
338 testBefore(functionReturningObj);
341 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
343 var expected = 'This is a normal link: bugaYahoo';
344 jQuery('<b>buga</b>').insertBefore('#yahoo');
345 equals( expected, jQuery('#en').text(), 'Insert String before' );
348 expected = "This is a normal link: Try them out:Yahoo";
349 jQuery(document.getElementById('first')).insertBefore('#yahoo');
350 equals( expected, jQuery('#en').text(), "Insert element before" );
353 expected = "This is a normal link: Try them out:diveintomarkYahoo";
354 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
355 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
358 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
359 jQuery("#first, #mark").insertBefore('#yahoo');
360 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
363 var testAfter = function(val) {
365 var expected = 'This is a normal link: Yahoobuga';
366 jQuery('#yahoo').after(val( '<b>buga</b>' ));
367 equals( expected, jQuery('#en').text(), 'Insert String after' );
370 expected = "This is a normal link: YahooTry them out:";
371 jQuery('#yahoo').after(val( document.getElementById('first') ));
372 equals( expected, jQuery('#en').text(), "Insert element after" );
375 expected = "This is a normal link: YahooTry them out:diveintomark";
376 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
377 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
380 expected = "This is a normal link: YahoodiveintomarkTry them out:";
381 jQuery('#yahoo').after(val( jQuery("#first, #mark") ));
382 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
385 test("after(String|Element|Array<Element>|jQuery)", function() {
389 test("after(Function)", function() {
390 testAfter(functionReturningObj);
393 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
395 var expected = 'This is a normal link: Yahoobuga';
396 jQuery('<b>buga</b>').insertAfter('#yahoo');
397 equals( expected, jQuery('#en').text(), 'Insert String after' );
400 expected = "This is a normal link: YahooTry them out:";
401 jQuery(document.getElementById('first')).insertAfter('#yahoo');
402 equals( expected, jQuery('#en').text(), "Insert element after" );
405 expected = "This is a normal link: YahooTry them out:diveintomark";
406 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
407 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
410 expected = "This is a normal link: YahoodiveintomarkTry them out:";
411 jQuery("#first, #mark").insertAfter('#yahoo');
412 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
415 var testReplaceWith = function(val) {
417 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
418 ok( jQuery("#replace")[0], 'Replace element with string' );
419 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
422 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
423 ok( jQuery("#first")[0], 'Replace element with element' );
424 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
427 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
428 ok( jQuery("#first")[0], 'Replace element with array of elements' );
429 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
430 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
433 jQuery('#yahoo').replaceWith(val( jQuery("#first, #mark") ));
434 ok( jQuery("#first")[0], 'Replace element with set of elements' );
435 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
436 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
439 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
440 testReplaceWith(bareObj);
443 test("replaceWith(Function)", function() {
444 testReplaceWith(functionReturningObj);
447 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
449 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
450 ok( jQuery("#replace")[0], 'Replace element with string' );
451 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
454 jQuery(document.getElementById('first')).replaceAll("#yahoo");
455 ok( jQuery("#first")[0], 'Replace element with element' );
456 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
459 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
460 ok( jQuery("#first")[0], 'Replace element with array of elements' );
461 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
462 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
465 jQuery("#first, #mark").replaceAll("#yahoo");
466 ok( jQuery("#first")[0], 'Replace element with set of elements' );
467 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
468 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
471 test("clone()", function() {
473 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
474 var clone = jQuery('#yahoo').clone();
475 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
476 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
479 "<table/>", "<tr/>", "<td/>", "<div/>",
480 "<button/>", "<ul/>", "<ol/>", "<li/>",
481 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
482 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
484 for (var i = 0; i < cloneTags.length; i++) {
485 var j = jQuery(cloneTags[i]);
486 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
489 // using contents will get comments regular, text, and comment nodes
490 var cl = jQuery("#nonnodes").contents().clone();
491 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
493 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
494 ok( true, "Bound event still exists." );
497 div = div.clone(true).clone(true);
498 equals( div.length, 1, "One element cloned" );
499 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
500 div.trigger("click");
502 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
503 div.find("table").click(function(){
504 ok( true, "Bound event still exists." );
507 div = div.clone(true);
508 equals( div.length, 1, "One element cloned" );
509 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
510 div.find("table:last").trigger("click");
512 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>');
514 div = div.clone(true);
515 equals( div.length, 1, "One element cloned" );
516 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
520 test("clone() on XML nodes", function() {
523 jQuery.get("data/dashboard.xml", function (xml) {
524 var root = jQuery(xml.documentElement).clone();
525 var origTab = jQuery("tab", xml).eq(0);
526 var cloneTab = jQuery("tab", root).eq(0);
527 origTab.text("origval");
528 cloneTab.text("cloneval");
529 equals(origTab.text(), "origval", "Check original XML node was correctly set");
530 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
536 test("val()", function() {
539 document.getElementById('text1').value = "bla";
540 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
544 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
545 // ticket #1714 this caused a JS error in IE
546 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
547 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
549 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
551 isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
553 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
555 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
557 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
561 var testVal = function(valueObj) {
564 jQuery("#text1").val(valueObj( 'test' ));
565 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
567 jQuery("#text1").val(valueObj( 67 ));
568 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
570 jQuery("#select1").val(valueObj( "3" ));
571 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
573 jQuery("#select1").val(valueObj( 2 ));
574 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
576 // using contents will get comments regular, text, and comment nodes
577 var j = jQuery("#nonnodes").contents();
578 j.val(valueObj( "asdf" ));
579 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
580 j.removeAttr("value");
583 test("val(String/Number)", function() {
587 test("val(Function)", function() {
588 testVal(functionReturningObj);
591 var testHtml = function(valueObj) {
596 jQuery.scriptorder = 0;
598 var div = jQuery("#main > div");
599 div.html(valueObj("<b>test</b>"));
601 for ( var i = 0; i < div.size(); i++ ) {
602 if ( div.get(i).childNodes.length != 1 ) pass = false;
604 ok( pass, "Set HTML" );
606 window.debug = false;
609 // using contents will get comments regular, text, and comment nodes
610 var j = jQuery("#nonnodes").contents();
611 j.html(valueObj("<b>bold</b>"));
613 // this is needed, or the expando added by jQuery unique will yield a different html
614 j.find('b').removeData();
615 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
617 jQuery("#main").html(valueObj("<select/>"));
618 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
619 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
621 var $div = jQuery('<div />');
622 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
623 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
627 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>'));
631 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>'));
633 jQuery("#main").html(valueObj('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'));
635 // 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
636 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>"));
638 setTimeout( start, 100 );
641 test("html(String)", function() {
645 test("html(Function)", function() {
646 testHtml(functionReturningObj);
649 var testText = function(valueObj) {
651 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" );
653 // using contents will get comments regular, text, and comment nodes
654 var j = jQuery("#nonnodes").contents();
656 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
657 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
658 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
661 test("text(String)", function() {
665 test("text(Function)", function() {
666 testText(functionReturningObj);
669 test("remove()", function() {
671 jQuery("#ap").children().remove();
672 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
673 equals( jQuery("#ap").children().length, 0, "Check remove" );
676 jQuery("#ap").children().remove("a");
677 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
678 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
680 jQuery("#ap").children().remove("a, code");
681 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
683 // using contents will get comments regular, text, and comment nodes
684 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
685 jQuery("#nonnodes").contents().remove();
686 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
689 test("empty()", function() {
691 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
692 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
694 // using contents will get comments regular, text, and comment nodes
695 var j = jQuery("#nonnodes").contents();
697 equals( j.html(), "", "Check node,textnode,comment empty works" );