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" );
44 // Wrap an element containing a text node
45 j = jQuery("<span/>").wrap("<div>test</div>");
46 equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
47 equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
50 test("wrap(String|Element)", function() {
54 test("wrap(Function)", function() {
55 testWrap(functionReturningObj);
58 var testWrapAll = function(val) {
60 var prev = jQuery("#firstp")[0].previousSibling;
61 var p = jQuery("#firstp,#first")[0].parentNode;
63 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
64 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
65 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
66 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
67 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
68 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
71 var prev = jQuery("#firstp")[0].previousSibling;
72 var p = jQuery("#first")[0].parentNode;
73 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
74 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
75 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
76 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
79 test("wrapAll(String|Element)", function() {
83 // TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
84 // test("wrapAll(Function)", function() {
85 // testWrapAll(functionReturningObj);
88 var testWrapInner = function(val) {
90 var num = jQuery("#first").children().length;
91 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
92 equals( jQuery("#first").children().length, 1, "Only one child" );
93 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
94 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
97 var num = jQuery("#first").children().length;
98 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
99 equals( jQuery("#first").children().length, 1, "Only one child" );
100 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
101 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
104 test("wrapInner(String|Element)", function() {
105 testWrapInner(bareObj);
108 // TODO: wrapInner uses wrapAll -- get wrapAll working with Function
109 // test("wrapInner(Function)", function() {
110 // testWrapInner(functionReturningObj)
113 var testAppend = function(valueObj) {
115 var defaultText = 'Try them out:'
116 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
117 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
118 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
121 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
122 jQuery('#sap').append(valueObj(document.getElementById('first')));
123 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
126 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
127 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
128 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
131 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
132 jQuery('#sap').append(valueObj(jQuery("#first, #yahoo")));
133 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
136 jQuery("#sap").append(valueObj( 5 ));
137 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
140 jQuery("#sap").append(valueObj( " text with spaces " ));
141 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
144 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
145 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
146 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
149 jQuery("#sap").append(valueObj( document.getElementById('form') ));
150 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
155 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append(valueObj( "<div>test</div>" ));
160 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
163 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
164 t( 'Append legend', '#legend', ['legend'] );
167 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
168 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
170 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
171 ok( jQuery('#table colgroup').length, "Append colgroup" );
173 jQuery('#table colgroup').append(valueObj( '<col/>' ));
174 ok( jQuery('#table colgroup col').length, "Append col" );
177 jQuery('#table').append(valueObj( '<caption></caption>' ));
178 ok( jQuery('#table caption').length, "Append caption" );
182 .append(valueObj( '<select id="appendSelect1"></select>' ))
183 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
185 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
187 // using contents will get comments regular, text, and comment nodes
188 var j = jQuery("#nonnodes").contents();
189 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
190 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
191 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
192 d.contents().appendTo("#nonnodes");
194 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
197 test("append(String|Element|Array<Element>|jQuery)", function() {
201 test("append(Function)", function() {
202 testAppend(functionReturningObj);
205 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
207 var defaultText = 'Try them out:'
208 jQuery('<b>buga</b>').appendTo('#first');
209 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
210 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
213 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
214 jQuery(document.getElementById('first')).appendTo('#sap');
215 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
218 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
219 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
220 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
223 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
226 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
227 jQuery("#first, #yahoo").appendTo('#sap');
228 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
231 jQuery('#select1').appendTo('#foo');
232 t( 'Append select', '#foo select', ['select1'] );
235 var div = jQuery("<div/>").click(function(){
236 ok(true, "Running a cloned click.");
238 div.appendTo("#main, #moretests");
240 jQuery("#main div:last").click();
241 jQuery("#moretests div:last").click();
244 var div = jQuery("<div/>").appendTo("#main, #moretests");
246 equals( div.length, 2, "appendTo returns the inserted elements" );
248 div.addClass("test");
250 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
251 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
256 var testPrepend = function(val) {
258 var defaultText = 'Try them out:'
259 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
260 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
261 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
264 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
265 jQuery('#sap').prepend(val( document.getElementById('first') ));
266 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
269 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
270 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
271 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
274 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
275 jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
276 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
279 test("prepend(String|Element|Array<Element>|jQuery)", function() {
280 testPrepend(bareObj);
283 test("prepend(Function)", function() {
284 testPrepend(functionReturningObj);
287 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
289 var defaultText = 'Try them out:'
290 jQuery('<b>buga</b>').prependTo('#first');
291 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
292 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
295 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
296 jQuery(document.getElementById('first')).prependTo('#sap');
297 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
300 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
301 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
302 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
305 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
306 jQuery("#first, #yahoo").prependTo('#sap');
307 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
310 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
311 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
313 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
316 var testBefore = function(val) {
318 var expected = 'This is a normal link: bugaYahoo';
319 jQuery('#yahoo').before(val( '<b>buga</b>' ));
320 equals( expected, jQuery('#en').text(), 'Insert String before' );
323 expected = "This is a normal link: Try them out:Yahoo";
324 jQuery('#yahoo').before(val( document.getElementById('first') ));
325 equals( expected, jQuery('#en').text(), "Insert element before" );
328 expected = "This is a normal link: Try them out:diveintomarkYahoo";
329 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
330 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
333 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
334 jQuery('#yahoo').before(val( jQuery("#first, #mark") ));
335 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
338 test("before(String|Element|Array<Element>|jQuery)", function() {
342 test("before(Function)", function() {
343 testBefore(functionReturningObj);
346 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
348 var expected = 'This is a normal link: bugaYahoo';
349 jQuery('<b>buga</b>').insertBefore('#yahoo');
350 equals( expected, jQuery('#en').text(), 'Insert String before' );
353 expected = "This is a normal link: Try them out:Yahoo";
354 jQuery(document.getElementById('first')).insertBefore('#yahoo');
355 equals( expected, jQuery('#en').text(), "Insert element before" );
358 expected = "This is a normal link: Try them out:diveintomarkYahoo";
359 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
360 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
363 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
364 jQuery("#first, #mark").insertBefore('#yahoo');
365 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
368 var testAfter = function(val) {
370 var expected = 'This is a normal link: Yahoobuga';
371 jQuery('#yahoo').after(val( '<b>buga</b>' ));
372 equals( expected, jQuery('#en').text(), 'Insert String after' );
375 expected = "This is a normal link: YahooTry them out:";
376 jQuery('#yahoo').after(val( document.getElementById('first') ));
377 equals( expected, jQuery('#en').text(), "Insert element after" );
380 expected = "This is a normal link: YahooTry them out:diveintomark";
381 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
382 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
385 expected = "This is a normal link: YahoodiveintomarkTry them out:";
386 jQuery('#yahoo').after(val( jQuery("#first, #mark") ));
387 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
390 test("after(String|Element|Array<Element>|jQuery)", function() {
394 test("after(Function)", function() {
395 testAfter(functionReturningObj);
398 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
400 var expected = 'This is a normal link: Yahoobuga';
401 jQuery('<b>buga</b>').insertAfter('#yahoo');
402 equals( expected, jQuery('#en').text(), 'Insert String after' );
405 expected = "This is a normal link: YahooTry them out:";
406 jQuery(document.getElementById('first')).insertAfter('#yahoo');
407 equals( expected, jQuery('#en').text(), "Insert element after" );
410 expected = "This is a normal link: YahooTry them out:diveintomark";
411 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
412 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
415 expected = "This is a normal link: YahoodiveintomarkTry them out:";
416 jQuery("#first, #mark").insertAfter('#yahoo');
417 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
420 var testReplaceWith = function(val) {
422 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
423 ok( jQuery("#replace")[0], 'Replace element with string' );
424 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
427 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
428 ok( jQuery("#first")[0], 'Replace element with element' );
429 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
432 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
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('#yahoo').replaceWith(val( jQuery("#first, #mark") ));
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("replaceWith(String|Element|Array<Element>|jQuery)", function() {
445 testReplaceWith(bareObj);
448 test("replaceWith(Function)", function() {
449 testReplaceWith(functionReturningObj);
452 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
454 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
455 ok( jQuery("#replace")[0], 'Replace element with string' );
456 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
459 jQuery(document.getElementById('first')).replaceAll("#yahoo");
460 ok( jQuery("#first")[0], 'Replace element with element' );
461 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
464 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
465 ok( jQuery("#first")[0], 'Replace element with array of elements' );
466 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
467 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
470 jQuery("#first, #mark").replaceAll("#yahoo");
471 ok( jQuery("#first")[0], 'Replace element with set of elements' );
472 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
473 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
476 test("clone()", function() {
478 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
479 var clone = jQuery('#yahoo').clone();
480 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
481 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
484 "<table/>", "<tr/>", "<td/>", "<div/>",
485 "<button/>", "<ul/>", "<ol/>", "<li/>",
486 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
487 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
489 for (var i = 0; i < cloneTags.length; i++) {
490 var j = jQuery(cloneTags[i]);
491 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
494 // using contents will get comments regular, text, and comment nodes
495 var cl = jQuery("#nonnodes").contents().clone();
496 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
498 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
499 ok( true, "Bound event still exists." );
502 div = div.clone(true).clone(true);
503 equals( div.length, 1, "One element cloned" );
504 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
505 div.trigger("click");
507 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
508 div.find("table").click(function(){
509 ok( true, "Bound event still exists." );
512 div = div.clone(true);
513 equals( div.length, 1, "One element cloned" );
514 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
515 div.find("table:last").trigger("click");
517 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>');
519 div = div.clone(true);
520 equals( div.length, 1, "One element cloned" );
521 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
525 test("clone() on XML nodes", function() {
528 jQuery.get("data/dashboard.xml", function (xml) {
529 var root = jQuery(xml.documentElement).clone();
530 var origTab = jQuery("tab", xml).eq(0);
531 var cloneTab = jQuery("tab", root).eq(0);
532 origTab.text("origval");
533 cloneTab.text("cloneval");
534 equals(origTab.text(), "origval", "Check original XML node was correctly set");
535 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
541 test("val()", function() {
544 document.getElementById('text1').value = "bla";
545 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
549 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
550 // ticket #1714 this caused a JS error in IE
551 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
552 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
554 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
556 isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
558 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
560 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
562 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
566 var testVal = function(valueObj) {
569 jQuery("#text1").val(valueObj( 'test' ));
570 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
572 jQuery("#text1").val(valueObj( 67 ));
573 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
575 jQuery("#select1").val(valueObj( "3" ));
576 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
578 jQuery("#select1").val(valueObj( 2 ));
579 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
581 // using contents will get comments regular, text, and comment nodes
582 var j = jQuery("#nonnodes").contents();
583 j.val(valueObj( "asdf" ));
584 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
585 j.removeAttr("value");
588 test("val(String/Number)", function() {
592 test("val(Function)", function() {
593 testVal(functionReturningObj);
596 var testHtml = function(valueObj) {
601 jQuery.scriptorder = 0;
603 var div = jQuery("#main > div");
604 div.html(valueObj("<b>test</b>"));
606 for ( var i = 0; i < div.size(); i++ ) {
607 if ( div.get(i).childNodes.length != 1 ) pass = false;
609 ok( pass, "Set HTML" );
611 window.debug = false;
614 // using contents will get comments regular, text, and comment nodes
615 var j = jQuery("#nonnodes").contents();
616 j.html(valueObj("<b>bold</b>"));
618 // this is needed, or the expando added by jQuery unique will yield a different html
619 j.find('b').removeData();
620 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
622 jQuery("#main").html(valueObj("<select/>"));
623 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
624 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
626 var $div = jQuery('<div />');
627 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
628 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
632 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>'));
636 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>'));
638 jQuery("#main").html(valueObj('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>'));
640 // 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
641 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>"));
643 setTimeout( start, 100 );
646 test("html(String)", function() {
650 test("html(Function)", function() {
651 testHtml(functionReturningObj);
654 var testText = function(valueObj) {
656 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" );
658 // using contents will get comments regular, text, and comment nodes
659 var j = jQuery("#nonnodes").contents();
661 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
662 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
663 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
666 test("text(String)", function() {
670 test("text(Function)", function() {
671 testText(functionReturningObj);
674 test("remove()", function() {
676 jQuery("#ap").children().remove();
677 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
678 equals( jQuery("#ap").children().length, 0, "Check remove" );
681 jQuery("#ap").children().remove("a");
682 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
683 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
685 jQuery("#ap").children().remove("a, code");
686 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
688 // using contents will get comments regular, text, and comment nodes
689 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
690 jQuery("#nonnodes").contents().remove();
691 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
694 test("empty()", function() {
696 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
697 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
699 // using contents will get comments regular, text, and comment nodes
700 var j = jQuery("#nonnodes").contents();
702 equals( j.html(), "", "Check node,textnode,comment empty works" );