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." );
49 // Try to wrap an element with multiple elements (should fail)
50 j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
51 equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
52 equals( j.length, 1, "There should only be one element (no cloning)." );
53 equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
56 test("wrap(String|Element)", function() {
60 test("wrap(Function)", function() {
61 testWrap(functionReturningObj);
64 var testWrapAll = function(val) {
66 var prev = jQuery("#firstp")[0].previousSibling;
67 var p = jQuery("#firstp,#first")[0].parentNode;
69 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
70 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
71 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
72 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
73 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
74 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
77 var prev = jQuery("#firstp")[0].previousSibling;
78 var p = jQuery("#first")[0].parentNode;
79 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
80 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
81 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
82 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
85 test("wrapAll(String|Element)", function() {
89 // TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
90 // test("wrapAll(Function)", function() {
91 // testWrapAll(functionReturningObj);
94 var testWrapInner = function(val) {
96 var num = jQuery("#first").children().length;
97 var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
98 equals( jQuery("#first").children().length, 1, "Only one child" );
99 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
100 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
103 var num = jQuery("#first").children().length;
104 var result = jQuery('#first').wrapInner(document.getElementById('empty'));
105 equals( jQuery("#first").children().length, 1, "Only one child" );
106 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
107 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
110 test("wrapInner(String|Element)", function() {
111 testWrapInner(bareObj);
114 // TODO: wrapInner uses wrapAll -- get wrapAll working with Function
115 // test("wrapInner(Function)", function() {
116 // testWrapInner(functionReturningObj)
119 var testAppend = function(valueObj) {
121 var defaultText = 'Try them out:'
122 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
123 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
124 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
127 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
128 jQuery('#sap').append(valueObj(document.getElementById('first')));
129 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
132 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
133 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
134 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
137 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
138 jQuery('#sap').append(valueObj(jQuery("#first, #yahoo")));
139 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
142 jQuery("#sap").append(valueObj( 5 ));
143 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
146 jQuery("#sap").append(valueObj( " text with spaces " ));
147 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
150 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
151 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
152 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
155 jQuery("#sap").append(valueObj( document.getElementById('form') ));
156 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
161 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append(valueObj( "<div>test</div>" ));
166 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
169 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
170 t( 'Append legend', '#legend', ['legend'] );
173 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
174 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
176 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
177 ok( jQuery('#table colgroup').length, "Append colgroup" );
179 jQuery('#table colgroup').append(valueObj( '<col/>' ));
180 ok( jQuery('#table colgroup col').length, "Append col" );
183 jQuery('#table').append(valueObj( '<caption></caption>' ));
184 ok( jQuery('#table caption').length, "Append caption" );
188 .append(valueObj( '<select id="appendSelect1"></select>' ))
189 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
191 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
193 // using contents will get comments regular, text, and comment nodes
194 var j = jQuery("#nonnodes").contents();
195 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
196 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
197 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
198 d.contents().appendTo("#nonnodes");
200 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
203 test("append(String|Element|Array<Element>|jQuery)", function() {
207 test("append(Function)", function() {
208 testAppend(functionReturningObj);
211 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
213 var defaultText = 'Try them out:'
214 jQuery('<b>buga</b>').appendTo('#first');
215 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
216 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
219 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
220 jQuery(document.getElementById('first')).appendTo('#sap');
221 equals( expected, jQuery('#sap').text(), "Check for appending of element" );
224 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
225 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
226 equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
229 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
232 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
233 jQuery("#first, #yahoo").appendTo('#sap');
234 equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
237 jQuery('#select1').appendTo('#foo');
238 t( 'Append select', '#foo select', ['select1'] );
241 var div = jQuery("<div/>").click(function(){
242 ok(true, "Running a cloned click.");
244 div.appendTo("#main, #moretests");
246 jQuery("#main div:last").click();
247 jQuery("#moretests div:last").click();
250 var div = jQuery("<div/>").appendTo("#main, #moretests");
252 equals( div.length, 2, "appendTo returns the inserted elements" );
254 div.addClass("test");
256 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
257 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
262 var testPrepend = function(val) {
264 var defaultText = 'Try them out:'
265 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
266 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
267 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
270 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
271 jQuery('#sap').prepend(val( document.getElementById('first') ));
272 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
275 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
276 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
277 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
280 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
281 jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
282 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
285 test("prepend(String|Element|Array<Element>|jQuery)", function() {
286 testPrepend(bareObj);
289 test("prepend(Function)", function() {
290 testPrepend(functionReturningObj);
293 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
295 var defaultText = 'Try them out:'
296 jQuery('<b>buga</b>').prependTo('#first');
297 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
298 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
301 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
302 jQuery(document.getElementById('first')).prependTo('#sap');
303 equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
306 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
307 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
308 equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
311 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
312 jQuery("#first, #yahoo").prependTo('#sap');
313 equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
316 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
317 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
319 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
322 var testBefore = function(val) {
324 var expected = 'This is a normal link: bugaYahoo';
325 jQuery('#yahoo').before(val( '<b>buga</b>' ));
326 equals( expected, jQuery('#en').text(), 'Insert String before' );
329 expected = "This is a normal link: Try them out:Yahoo";
330 jQuery('#yahoo').before(val( document.getElementById('first') ));
331 equals( expected, jQuery('#en').text(), "Insert element before" );
334 expected = "This is a normal link: Try them out:diveintomarkYahoo";
335 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
336 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
339 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
340 jQuery('#yahoo').before(val( jQuery("#first, #mark") ));
341 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
343 var set = jQuery("<div/>").before(val("<span>test</span>"));
344 equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
345 equals( set.length, 2, "Insert the element before the disconnected node." );
348 test("before(String|Element|Array<Element>|jQuery)", function() {
352 test("before(Function)", function() {
353 testBefore(functionReturningObj);
356 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
358 var expected = 'This is a normal link: bugaYahoo';
359 jQuery('<b>buga</b>').insertBefore('#yahoo');
360 equals( expected, jQuery('#en').text(), 'Insert String before' );
363 expected = "This is a normal link: Try them out:Yahoo";
364 jQuery(document.getElementById('first')).insertBefore('#yahoo');
365 equals( expected, jQuery('#en').text(), "Insert element before" );
368 expected = "This is a normal link: Try them out:diveintomarkYahoo";
369 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
370 equals( expected, jQuery('#en').text(), "Insert array of elements before" );
373 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
374 jQuery("#first, #mark").insertBefore('#yahoo');
375 equals( expected, jQuery('#en').text(), "Insert jQuery before" );
378 var testAfter = function(val) {
380 var expected = 'This is a normal link: Yahoobuga';
381 jQuery('#yahoo').after(val( '<b>buga</b>' ));
382 equals( expected, jQuery('#en').text(), 'Insert String after' );
385 expected = "This is a normal link: YahooTry them out:";
386 jQuery('#yahoo').after(val( document.getElementById('first') ));
387 equals( expected, jQuery('#en').text(), "Insert element after" );
390 expected = "This is a normal link: YahooTry them out:diveintomark";
391 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
392 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
395 expected = "This is a normal link: YahoodiveintomarkTry them out:";
396 jQuery('#yahoo').after(val( jQuery("#first, #mark") ));
397 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
399 var set = jQuery("<div/>").after(val("<span>test</span>"));
400 equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
401 equals( set.length, 2, "Insert the element after the disconnected node." );
404 test("after(String|Element|Array<Element>|jQuery)", function() {
408 test("after(Function)", function() {
409 testAfter(functionReturningObj);
412 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
414 var expected = 'This is a normal link: Yahoobuga';
415 jQuery('<b>buga</b>').insertAfter('#yahoo');
416 equals( expected, jQuery('#en').text(), 'Insert String after' );
419 expected = "This is a normal link: YahooTry them out:";
420 jQuery(document.getElementById('first')).insertAfter('#yahoo');
421 equals( expected, jQuery('#en').text(), "Insert element after" );
424 expected = "This is a normal link: YahooTry them out:diveintomark";
425 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
426 equals( expected, jQuery('#en').text(), "Insert array of elements after" );
429 expected = "This is a normal link: YahoodiveintomarkTry them out:";
430 jQuery("#first, #mark").insertAfter('#yahoo');
431 equals( expected, jQuery('#en').text(), "Insert jQuery after" );
434 var testReplaceWith = function(val) {
436 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
437 ok( jQuery("#replace")[0], 'Replace element with string' );
438 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
441 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
442 ok( jQuery("#first")[0], 'Replace element with element' );
443 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
446 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
447 ok( jQuery("#first")[0], 'Replace element with array of elements' );
448 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
449 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
452 jQuery('#yahoo').replaceWith(val( jQuery("#first, #mark") ));
453 ok( jQuery("#first")[0], 'Replace element with set of elements' );
454 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
455 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
457 var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
458 equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
459 equals( set.length, 1, "Replace the disconnected node." );
462 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
463 testReplaceWith(bareObj);
466 test("replaceWith(Function)", function() {
467 testReplaceWith(functionReturningObj);
470 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
472 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
473 ok( jQuery("#replace")[0], 'Replace element with string' );
474 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
477 jQuery(document.getElementById('first')).replaceAll("#yahoo");
478 ok( jQuery("#first")[0], 'Replace element with element' );
479 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
482 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
483 ok( jQuery("#first")[0], 'Replace element with array of elements' );
484 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
485 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
488 jQuery("#first, #mark").replaceAll("#yahoo");
489 ok( jQuery("#first")[0], 'Replace element with set of elements' );
490 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
491 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
494 test("clone()", function() {
496 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
497 var clone = jQuery('#yahoo').clone();
498 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
499 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
502 "<table/>", "<tr/>", "<td/>", "<div/>",
503 "<button/>", "<ul/>", "<ol/>", "<li/>",
504 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
505 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
507 for (var i = 0; i < cloneTags.length; i++) {
508 var j = jQuery(cloneTags[i]);
509 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
512 // using contents will get comments regular, text, and comment nodes
513 var cl = jQuery("#nonnodes").contents().clone();
514 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
516 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
517 ok( true, "Bound event still exists." );
520 div = div.clone(true).clone(true);
521 equals( div.length, 1, "One element cloned" );
522 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
523 div.trigger("click");
525 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
526 div.find("table").click(function(){
527 ok( true, "Bound event still exists." );
530 div = div.clone(true);
531 equals( div.length, 1, "One element cloned" );
532 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
533 div.find("table:last").trigger("click");
535 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>');
537 div = div.clone(true);
538 equals( div.length, 1, "One element cloned" );
539 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
543 test("clone() on XML nodes", function() {
546 jQuery.get("data/dashboard.xml", function (xml) {
547 var root = jQuery(xml.documentElement).clone();
548 var origTab = jQuery("tab", xml).eq(0);
549 var cloneTab = jQuery("tab", root).eq(0);
550 origTab.text("origval");
551 cloneTab.text("cloneval");
552 equals(origTab.text(), "origval", "Check original XML node was correctly set");
553 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
559 test("val()", function() {
562 document.getElementById('text1').value = "bla";
563 equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
567 equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
568 // ticket #1714 this caused a JS error in IE
569 equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
570 ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
572 equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
574 isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
576 equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
578 equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
580 equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
584 var testVal = function(valueObj) {
587 jQuery("#text1").val(valueObj( 'test' ));
588 equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
590 jQuery("#text1").val(valueObj( 67 ));
591 equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
593 jQuery("#select1").val(valueObj( "3" ));
594 equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
596 jQuery("#select1").val(valueObj( 2 ));
597 equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
599 // using contents will get comments regular, text, and comment nodes
600 var j = jQuery("#nonnodes").contents();
601 j.val(valueObj( "asdf" ));
602 equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
603 j.removeAttr("value");
606 test("val(String/Number)", function() {
610 test("val(Function)", function() {
611 testVal(functionReturningObj);
614 var testHtml = function(valueObj) {
619 jQuery.scriptorder = 0;
621 var div = jQuery("#main > div");
622 div.html(valueObj("<b>test</b>"));
624 for ( var i = 0; i < div.size(); i++ ) {
625 if ( div.get(i).childNodes.length != 1 ) pass = false;
627 ok( pass, "Set HTML" );
629 window.debug = false;
632 // using contents will get comments regular, text, and comment nodes
633 var j = jQuery("#nonnodes").contents();
634 j.html(valueObj("<b>bold</b>"));
636 // this is needed, or the expando added by jQuery unique will yield a different html
637 j.find('b').removeData();
638 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
640 jQuery("#main").html(valueObj("<select/>"));
641 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
642 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
644 var $div = jQuery('<div />');
645 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
646 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
650 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>'));
654 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
656 jQuery("#main").html(valueObj('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)" );</script></form>'));
658 // 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
659 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>"));
661 setTimeout( start, 100 );
664 test("html(String)", function() {
668 test("html(Function)", function() {
669 testHtml(functionReturningObj);
672 var testText = function(valueObj) {
674 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" );
676 // using contents will get comments regular, text, and comment nodes
677 var j = jQuery("#nonnodes").contents();
679 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
680 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
681 equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
684 test("text(String)", function() {
688 test("text(Function)", function() {
689 testText(functionReturningObj);
692 var testRemove = function(method) {
695 var first = jQuery("#ap").children(":first");
696 first.data("foo", "bar");
698 jQuery("#ap").children()[method]();
699 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
700 equals( jQuery("#ap").children().length, 0, "Check remove" );
702 equals( first.data("foo"), method == "remove" ? null : "bar" );
705 jQuery("#ap").children()[method]("a");
706 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
707 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
709 jQuery("#ap").children()[method]("a, code");
710 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
712 // using contents will get comments regular, text, and comment nodes
713 equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
714 jQuery("#nonnodes").contents()[method]();
715 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
720 var first = jQuery("#ap").children(":first");
721 var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
723 equals( method == "remove" ? 0 : 1, count );
728 test("remove()", function() {
729 testRemove("remove");
732 test("detach()", function() {
733 testRemove("detach");
736 test("empty()", function() {
738 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
739 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
741 // using contents will get comments regular, text, and comment nodes
742 var j = jQuery("#nonnodes").contents();
744 equals( j.html(), "", "Check node,textnode,comment empty works" );