3 test("Basic requirements", function() {
5 ok( Array.prototype.push, "Array.push()" );
6 ok( Function.prototype.apply, "Function.apply()" );
7 ok( document.getElementById, "getElementById" );
8 ok( document.getElementsByTagName, "getElementsByTagName" );
9 ok( RegExp, "RegExp" );
10 ok( jQuery, "jQuery" );
14 test("$()", function() {
17 var main = $("#main");
18 isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
21 // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22 // what the expected behavior should even be. FF returns "\n" for the text node
23 // make sure this is handled
24 var crlfContainer = $('<p>\r\n</p>');
25 var x = crlfContainer.contents().get(0).nodeValue;
26 equals( x, what???, "Check for \\r and \\n in jQuery()" );
29 /* // Disabled until we add this functionality in
32 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
36 ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
38 var code = $("<code/>");
39 equals( code.length, 1, "Correct number of elements generated for code" );
40 var img = $("<img/>");
41 equals( img.length, 1, "Correct number of elements generated for img" );
42 var div = $("<div/><hr/><code/><b/>");
43 equals( div.length, 4, "Correct number of elements generated for div hr code b" );
46 test("noConflict", function() {
50 var newjQuery = jQuery.noConflict();
52 ok( newjQuery == old, "noConflict returned the jQuery object" );
53 ok( jQuery == old, "Make sure jQuery wasn't touched." );
54 ok( $ == "$", "Make sure $ was reverted." );
58 newjQuery = jQuery.noConflict(true);
60 ok( newjQuery == old, "noConflict returned the jQuery object" );
61 ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
62 ok( $ == "$", "Make sure $ was reverted." );
67 test("isFunction", function() {
70 // Make sure that false values return false
71 ok( !jQuery.isFunction(), "No Value" );
72 ok( !jQuery.isFunction( null ), "null Value" );
73 ok( !jQuery.isFunction( undefined ), "undefined Value" );
74 ok( !jQuery.isFunction( "" ), "Empty String Value" );
75 ok( !jQuery.isFunction( 0 ), "0 Value" );
78 // Safari uses "(Internal Function)"
79 ok( jQuery.isFunction(String), "String Function" );
80 ok( jQuery.isFunction(Array), "Array Function" );
81 ok( jQuery.isFunction(Object), "Object Function" );
82 ok( jQuery.isFunction(Function), "Function Function" );
84 // When stringified, this could be misinterpreted
85 var mystr = "function";
86 ok( !jQuery.isFunction(mystr), "Function String" );
88 // When stringified, this could be misinterpreted
89 var myarr = [ "function" ];
90 ok( !jQuery.isFunction(myarr), "Function Array" );
92 // When stringified, this could be misinterpreted
93 var myfunction = { "function": "test" };
94 ok( !jQuery.isFunction(myfunction), "Function Object" );
96 // Make sure normal functions still work
97 var fn = function(){};
98 ok( jQuery.isFunction(fn), "Normal Function" );
100 var obj = document.createElement("object");
102 // Firefox says this is a function
103 ok( !jQuery.isFunction(obj), "Object Element" );
105 // IE says this is an object
106 ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
108 var nodes = document.body.childNodes;
110 // Safari says this is a function
111 ok( !jQuery.isFunction(nodes), "childNodes Property" );
113 var first = document.body.firstChild;
115 // Normal elements are reported ok everywhere
116 ok( !jQuery.isFunction(first), "A normal DOM Element" );
118 var input = document.createElement("input");
120 document.body.appendChild( input );
122 // IE says this is an object
123 ok( jQuery.isFunction(input.focus), "A default function property" );
125 document.body.removeChild( input );
127 var a = document.createElement("a");
128 a.href = "some-function";
129 document.body.appendChild( a );
131 // This serializes with the word 'function' in it
132 ok( !jQuery.isFunction(a), "Anchor Element" );
134 document.body.removeChild( a );
136 // Recursive function calls have lengths and array-like properties
137 function callme(callback){
138 function fn(response){
142 ok( jQuery.isFunction(fn), "Recursive Function Call" );
144 fn({ some: "data" });
148 callme(function(){});
154 test("$('html')", function() {
159 var s = $("<script>var foo='test';</script>")[0];
160 ok( s, "Creating a script" );
161 ok( !foo, "Make sure the script wasn't executed prematurely" );
163 ok( foo, "Executing a scripts contents in the right context" );
166 ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
171 test("$('html', context)", function() {
174 var $div = $("<div/>");
175 var $span = $("<span/>", $div);
176 equals($span.length, 1, "Verify a span created with a div context works, #1763");
179 test("$(selector, xml).text(str) - Loaded via XML document", function() {
182 $.get('data/dashboard.xml', function(xml) {
183 // tests for #1419 where IE was a problem
184 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
185 $("tab:first", xml).text("newtext");
186 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
191 test("length", function() {
193 ok( $("p").length == 6, "Get Number of Elements Found" );
196 test("size()", function() {
198 ok( $("p").size() == 6, "Get Number of Elements Found" );
201 test("get()", function() {
203 isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
206 test("get(Number)", function() {
208 ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
211 test("add(String|Element|Array|undefined)", function() {
213 isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
214 isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
215 ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
217 var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
218 ok( x[0].id == "x1", "Check on-the-fly element1" );
219 ok( x[1].id == "x2", "Check on-the-fly element2" );
221 var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
222 ok( x[0].id == "x1", "Check on-the-fly element1" );
223 ok( x[1].id == "x2", "Check on-the-fly element2" );
226 equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." );
229 test("each(Function)", function() {
232 div.each(function(){this.foo = 'zoo';});
234 for ( var i = 0; i < div.size(); i++ ) {
235 if ( div.get(i).foo != "zoo" ) pass = false;
237 ok( pass, "Execute a function, Relative" );
240 test("index(Object)", function() {
242 ok( $([window, document]).index(window) == 0, "Check for index of elements" );
243 ok( $([window, document]).index(document) == 1, "Check for index of elements" );
244 var inputElements = $('#radio1,#radio2,#check1,#check2');
245 ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
246 ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
247 ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
248 ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
249 ok( inputElements.index(window) == -1, "Check for not found index" );
250 ok( inputElements.index(document) == -1, "Check for not found index" );
253 test("attr(String)", function() {
255 ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
256 ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
257 ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
258 ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
259 ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
260 ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
261 ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
262 ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
263 ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
264 ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
265 ok( $('#name').attr('name') == "name", 'Check for name attribute' );
266 ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
267 ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
268 ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
269 ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
270 ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
271 ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
272 ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
273 ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
275 $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
276 ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
280 test("attr(String) in XML Files", function() {
283 $.get("data/dashboard.xml", function(xml) {
284 ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
285 ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
291 test("attr(String, Function)", function() {
293 ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
294 ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
297 test("attr(Hash)", function() {
300 $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
301 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
303 ok( pass, "Set Multiple Attributes" );
306 test("attr(String, Object)", function() {
309 div.attr("foo", "bar");
311 for ( var i = 0; i < div.size(); i++ ) {
312 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
314 ok( pass, "Set Attribute" );
316 ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
318 $("#name").attr('name', 'something');
319 ok( $("#name").attr('name') == 'something', 'Set name attribute' );
320 $("#check2").attr('checked', true);
321 ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
322 $("#check2").attr('checked', false);
323 ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
324 $("#text1").attr('readonly', true);
325 ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
326 $("#text1").attr('readonly', false);
327 ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
328 $("#name").attr('maxlength', '5');
329 ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
330 $("#name").attr('maxLength', '10');
331 ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
334 $("#name").attr('someAttr', '0');
335 equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
336 $("#name").attr('someAttr', 0);
337 equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
338 $("#name").attr('someAttr', 1);
339 equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
343 var type = $("#check2").attr('type');
346 $("#check2").attr('type','hidden');
350 ok( thrown, "Exception thrown when trying to change type property" );
351 equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
353 var check = document.createElement("input");
356 $(check).attr('type','checkbox');
360 ok( thrown, "Exception thrown when trying to change type property" );
361 equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
365 test("attr(String, Object) - Loaded via XML document", function() {
368 $.get('data/dashboard.xml', function(xml) {
370 $('tab', xml).each(function() {
371 titles.push($(this).attr('title'));
373 equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
374 equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
380 test("css(String|Hash)", function() {
383 ok( $('#main').css("display") == 'none', 'Check for css property "display"');
385 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
386 $('#foo').css({display: 'none'});
387 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
388 $('#foo').css({display: 'block'});
389 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
391 $('#floatTest').css({styleFloat: 'right'});
392 ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
393 $('#floatTest').css({cssFloat: 'left'});
394 ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
395 $('#floatTest').css({'float': 'right'});
396 ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
397 $('#floatTest').css({'font-size': '30px'});
398 ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
400 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
401 $('#foo').css({opacity: n});
402 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
403 $('#foo').css({opacity: parseFloat(n)});
404 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
406 $('#foo').css({opacity: ''});
407 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
410 test("css(String, Object)", function() {
412 ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
413 $('#foo').css('display', 'none');
414 ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
415 $('#foo').css('display', 'block');
416 ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
418 $('#floatTest').css('styleFloat', 'left');
419 ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
420 $('#floatTest').css('cssFloat', 'right');
421 ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
422 $('#floatTest').css('float', 'left');
423 ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
424 $('#floatTest').css('font-size', '20px');
425 ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
427 $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
428 $('#foo').css('opacity', n);
429 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
430 $('#foo').css('opacity', parseFloat(n));
431 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
433 $('#foo').css('opacity', '');
434 ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
435 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
436 if (jQuery.browser.msie) {
437 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
439 equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
442 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
445 var $checkedtest = $("#checkedtest");
446 // IE6 was clearing "checked" in jQuery.css(elem, "height");
447 jQuery.css($checkedtest[0], "height");
448 ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
449 ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
450 ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
451 ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
454 test("width()", function() {
457 $("#nothiddendiv").width(30);
458 equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly");
459 $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599
460 equals($("#nothiddendiv").width(), 30, "Test negative width ignored");
463 test("text()", function() {
465 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
466 ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
469 test("wrap(String|Element)", function() {
471 var defaultText = 'Try them out:'
472 var result = $('#first').wrap('<div class="red"><span></span></div>').text();
473 ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
474 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
477 var defaultText = 'Try them out:'
478 var result = $('#first').wrap(document.getElementById('empty')).parent();
479 ok( result.is('ol'), 'Check for element wrapping' );
480 ok( result.text() == defaultText, 'Check for element wrapping' );
483 $('#check1').click(function() {
485 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
486 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
487 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
491 test("wrapAll(String|Element)", function() {
493 var prev = $("#first")[0].previousSibling;
494 var p = $("#first")[0].parentNode;
495 var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
496 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
497 ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
498 ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
499 equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
500 equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
503 var prev = $("#first")[0].previousSibling;
504 var p = $("#first")[0].parentNode;
505 var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
506 equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
507 equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
508 equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
511 test("wrapInner(String|Element)", function() {
513 var num = $("#first").children().length;
514 var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
515 equals( $("#first").children().length, 1, "Only one child" );
516 ok( $("#first").children().is(".red"), "Verify Right Element" );
517 equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
520 var num = $("#first").children().length;
521 var result = $('#first').wrapInner(document.getElementById('empty'));
522 equals( $("#first").children().length, 1, "Only one child" );
523 ok( $("#first").children().is("#empty"), "Verify Right Element" );
524 equals( $("#first").children().children().length, num, "Verify Elements Intact" );
527 test("append(String|Element|Array<Element>|jQuery)", function() {
529 var defaultText = 'Try them out:'
530 var result = $('#first').append('<b>buga</b>');
531 ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
532 ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
535 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
536 $('#sap').append(document.getElementById('first'));
537 ok( expected == $('#sap').text(), "Check for appending of element" );
540 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
541 $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
542 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
545 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
546 $('#sap').append($("#first, #yahoo"));
547 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
550 $("#sap").append( 5 );
551 ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
554 $("#sap").append( " text with spaces " );
555 ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
558 ok( $("#sap").append([]), "Check for appending an empty array." );
559 ok( $("#sap").append(""), "Check for appending an empty string." );
560 ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
563 $("#sap").append(document.getElementById('form'));
564 ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
569 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
574 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
577 $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
578 t( 'Append legend', '#legend', ['legend'] );
581 $('#select1').append('<OPTION>Test</OPTION>');
582 ok( $('#select1 option:last').text() == "Test", "Appending <OPTION> (all caps)" );
584 $('#table').append('<colgroup></colgroup>');
585 ok( $('#table colgroup').length, "Append colgroup" );
587 $('#table colgroup').append('<col/>');
588 ok( $('#table colgroup col').length, "Append col" );
591 $('#table').append('<caption></caption>');
592 ok( $('#table caption').length, "Append caption" );
596 .append('<select id="appendSelect1"></select>')
597 .append('<select id="appendSelect2"><option>Test</option></select>');
599 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
602 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
604 var defaultText = 'Try them out:'
605 $('<b>buga</b>').appendTo('#first');
606 ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
607 ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
610 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
611 $(document.getElementById('first')).appendTo('#sap');
612 ok( expected == $('#sap').text(), "Check for appending of element" );
615 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
616 $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
617 ok( expected == $('#sap').text(), "Check for appending of array of elements" );
620 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
621 $("#first, #yahoo").appendTo('#sap');
622 ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
625 $('#select1').appendTo('#foo');
626 t( 'Append select', '#foo select', ['select1'] );
629 test("prepend(String|Element|Array<Element>|jQuery)", function() {
631 var defaultText = 'Try them out:'
632 var result = $('#first').prepend('<b>buga</b>');
633 ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
634 ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
637 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
638 $('#sap').prepend(document.getElementById('first'));
639 ok( expected == $('#sap').text(), "Check for prepending of element" );
642 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
643 $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
644 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
647 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
648 $('#sap').prepend($("#first, #yahoo"));
649 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
652 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
654 var defaultText = 'Try them out:'
655 $('<b>buga</b>').prependTo('#first');
656 ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
657 ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
660 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
661 $(document.getElementById('first')).prependTo('#sap');
662 ok( expected == $('#sap').text(), "Check for prepending of element" );
665 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
666 $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
667 ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
670 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
671 $("#yahoo, #first").prependTo('#sap');
672 ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
675 $('<select id="prependSelect1"></select>').prependTo('form:last');
676 $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
678 t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
681 test("before(String|Element|Array<Element>|jQuery)", function() {
683 var expected = 'This is a normal link: bugaYahoo';
684 $('#yahoo').before('<b>buga</b>');
685 ok( expected == $('#en').text(), 'Insert String before' );
688 expected = "This is a normal link: Try them out:Yahoo";
689 $('#yahoo').before(document.getElementById('first'));
690 ok( expected == $('#en').text(), "Insert element before" );
693 expected = "This is a normal link: Try them out:diveintomarkYahoo";
694 $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
695 ok( expected == $('#en').text(), "Insert array of elements before" );
698 expected = "This is a normal link: Try them out:diveintomarkYahoo";
699 $('#yahoo').before($("#first, #mark"));
700 ok( expected == $('#en').text(), "Insert jQuery before" );
703 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
705 var expected = 'This is a normal link: bugaYahoo';
706 $('<b>buga</b>').insertBefore('#yahoo');
707 ok( expected == $('#en').text(), 'Insert String before' );
710 expected = "This is a normal link: Try them out:Yahoo";
711 $(document.getElementById('first')).insertBefore('#yahoo');
712 ok( expected == $('#en').text(), "Insert element before" );
715 expected = "This is a normal link: Try them out:diveintomarkYahoo";
716 $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
717 ok( expected == $('#en').text(), "Insert array of elements before" );
720 expected = "This is a normal link: Try them out:diveintomarkYahoo";
721 $("#first, #mark").insertBefore('#yahoo');
722 ok( expected == $('#en').text(), "Insert jQuery before" );
725 test("after(String|Element|Array<Element>|jQuery)", function() {
727 var expected = 'This is a normal link: Yahoobuga';
728 $('#yahoo').after('<b>buga</b>');
729 ok( expected == $('#en').text(), 'Insert String after' );
732 expected = "This is a normal link: YahooTry them out:";
733 $('#yahoo').after(document.getElementById('first'));
734 ok( expected == $('#en').text(), "Insert element after" );
737 expected = "This is a normal link: YahooTry them out:diveintomark";
738 $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
739 ok( expected == $('#en').text(), "Insert array of elements after" );
742 expected = "This is a normal link: YahooTry them out:diveintomark";
743 $('#yahoo').after($("#first, #mark"));
744 ok( expected == $('#en').text(), "Insert jQuery after" );
747 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
749 var expected = 'This is a normal link: Yahoobuga';
750 $('<b>buga</b>').insertAfter('#yahoo');
751 ok( expected == $('#en').text(), 'Insert String after' );
754 expected = "This is a normal link: YahooTry them out:";
755 $(document.getElementById('first')).insertAfter('#yahoo');
756 ok( expected == $('#en').text(), "Insert element after" );
759 expected = "This is a normal link: YahooTry them out:diveintomark";
760 $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
761 ok( expected == $('#en').text(), "Insert array of elements after" );
764 expected = "This is a normal link: YahooTry them out:diveintomark";
765 $("#mark, #first").insertAfter('#yahoo');
766 ok( expected == $('#en').text(), "Insert jQuery after" );
769 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
771 $('#yahoo').replaceWith('<b id="replace">buga</b>');
772 ok( $("#replace")[0], 'Replace element with string' );
773 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
776 $('#yahoo').replaceWith(document.getElementById('first'));
777 ok( $("#first")[0], 'Replace element with element' );
778 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
781 $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
782 ok( $("#first")[0], 'Replace element with array of elements' );
783 ok( $("#mark")[0], 'Replace element with array of elements' );
784 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
787 $('#yahoo').replaceWith($("#first, #mark"));
788 ok( $("#first")[0], 'Replace element with set of elements' );
789 ok( $("#mark")[0], 'Replace element with set of elements' );
790 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
793 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
795 $('<b id="replace">buga</b>').replaceAll("#yahoo");
796 ok( $("#replace")[0], 'Replace element with string' );
797 ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
800 $(document.getElementById('first')).replaceAll("#yahoo");
801 ok( $("#first")[0], 'Replace element with element' );
802 ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
805 $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
806 ok( $("#first")[0], 'Replace element with array of elements' );
807 ok( $("#mark")[0], 'Replace element with array of elements' );
808 ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
811 $("#first, #mark").replaceAll("#yahoo");
812 ok( $("#first")[0], 'Replace element with set of elements' );
813 ok( $("#mark")[0], 'Replace element with set of elements' );
814 ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
817 test("end()", function() {
819 ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
820 ok( $('#yahoo').end(), 'Check for end with nothing to end' );
824 ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
827 test("find(String)", function() {
829 ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
832 test("clone()", function() {
834 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
835 var clone = $('#yahoo').clone();
836 ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
837 ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
840 test("is(String)", function() {
842 ok( $('#form').is('form'), 'Check for element: A form must be a form' );
843 ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
844 ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
845 ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
846 ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
847 ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
848 ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
849 ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
850 ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
851 ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
852 ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
853 ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
854 ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
855 ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
856 ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
857 ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
858 ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
859 ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
860 ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
861 ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
862 ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
863 ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
865 // test is() with comma-seperated expressions
866 ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
867 ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
868 ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
869 ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
872 test("$.extend(Object, Object)", function() {
875 var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
876 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
877 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
878 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
879 deep1 = { foo: { bar: true } },
880 deep1copy = { foo: { bar: true } },
881 deep2 = { foo: { baz: true }, foo2: document },
882 deep2copy = { foo: { baz: true }, foo2: document },
883 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
885 jQuery.extend(settings, options);
886 isObj( settings, merged, "Check if extended: settings must be extended" );
887 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
889 jQuery.extend(settings, null, options);
890 isObj( settings, merged, "Check if extended: settings must be extended" );
891 isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
893 jQuery.extend(true, deep1, deep2);
894 isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
895 isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
896 equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
899 var recursive = { foo:target, bar:5 };
900 jQuery.extend(true, target, recursive);
901 isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
903 var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
904 ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
906 var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
907 ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
909 var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
910 ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
912 var obj = { foo:null };
913 jQuery.extend(true, obj, { foo:"notnull" } );
914 equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
917 jQuery.extend(func, { key: "value" } );
918 equals( func.key, "value", "Verify a function can be extended" );
920 var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
921 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
922 options1 = { xnumber2: 1, xstring2: "x" },
923 options1Copy = { xnumber2: 1, xstring2: "x" },
924 options2 = { xstring2: "xx", xxx: "newstringx" },
925 options2Copy = { xstring2: "xx", xxx: "newstringx" },
926 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
928 var settings = jQuery.extend({}, defaults, options1, options2);
929 isObj( settings, merged2, "Check if extended: settings must be extended" );
930 isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
931 isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
932 isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
935 test("val()", function() {
937 ok( $("#text1").val() == "Test", "Check for value of input element" );
938 ok( !$("#text1").val() == "", "Check for value of input element" );
939 // ticket #1714 this caused a JS error in IE
940 ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
943 test("val(String)", function() {
945 document.getElementById('text1').value = "bla";
946 ok( $("#text1").val() == "bla", "Check for modified value of input element" );
947 $("#text1").val('test');
948 ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
950 $("#select1").val("3");
951 ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
956 test("html(String)", function() {
958 var div = $("#main > div");
959 div.html("<b>test</b>");
961 for ( var i = 0; i < div.size(); i++ ) {
962 if ( div.get(i).childNodes.length != 1 ) pass = false;
964 ok( pass, "Set HTML" );
966 $("#main").html("<select/>");
967 $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
968 equals( $("#main select").val(), "O2", "Selected option correct" );
972 $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
974 $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
976 $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
978 setTimeout( start, 100 );
981 test("filter()", function() {
983 isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
984 isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
985 isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
986 isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
989 test("not()", function() {
991 ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
992 isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
993 isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
996 test("andSelf()", function() {
998 isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
999 isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1000 isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
1001 isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1004 test("siblings([String])", function() {
1006 isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1007 isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
1008 isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1009 isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1010 isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1013 test("children([String])", function() {
1015 isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1016 isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1017 isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1020 test("parent([String])", function() {
1022 ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
1023 ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
1024 ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
1025 ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
1026 isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1029 test("parents([String])", function() {
1031 ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
1032 ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
1033 ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
1034 isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1035 isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1038 test("next([String])", function() {
1040 ok( $("#ap").next()[0].id == "foo", "Simple next check" );
1041 ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
1042 ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
1043 ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
1046 test("prev([String])", function() {
1048 ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
1049 ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
1050 ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
1051 ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
1054 test("show()", function() {
1056 var pass = true, div = $("div");
1057 div.show().each(function(){
1058 if ( this.style.display == "none" ) pass = false;
1063 test("addClass(String)", function() {
1066 div.addClass("test");
1068 for ( var i = 0; i < div.size(); i++ ) {
1069 if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1071 ok( pass, "Add Class" );
1074 test("removeClass(String) - simple", function() {
1076 var div = $("div").addClass("test").removeClass("test"),
1078 for ( var i = 0; i < div.size(); i++ ) {
1079 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
1081 ok( pass, "Remove Class" );
1084 var div = $("div").addClass("test").addClass("foo").addClass("bar");
1085 div.removeClass("test").removeClass("bar").removeClass("foo");
1087 for ( var i = 0; i < div.size(); i++ ) {
1088 if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1090 ok( pass, "Remove multiple classes" );
1093 var div = $("div:eq(0)").addClass("test").removeClass("");
1094 ok( div.is('.test'), "Empty string passed to removeClass" );
1098 test("toggleClass(String)", function() {
1100 var e = $("#firstp");
1101 ok( !e.is(".test"), "Assert class not present" );
1102 e.toggleClass("test");
1103 ok( e.is(".test"), "Assert class present" );
1104 e.toggleClass("test");
1105 ok( !e.is(".test"), "Assert class not present" );
1108 test("removeAttr(String", function() {
1110 ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1113 test("text(String)", function() {
1115 ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
1118 test("$.each(Object,Function)", function() {
1120 $.each( [0,1,2], function(i, n){
1121 ok( i == n, "Check array iteration" );
1124 $.each( [5,6,7], function(i, n){
1125 ok( i == n - 5, "Check array iteration" );
1128 $.each( { name: "name", lang: "lang" }, function(i, n){
1129 ok( i == n, "Check object iteration" );
1133 test("$.prop", function() {
1135 var handle = function() { return this.id };
1136 ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1137 ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1140 test("$.className", function() {
1142 var x = $("<p>Hi</p>")[0];
1143 var c = $.className;
1145 ok( x.className == "hi", "Check single added class" );
1146 c.add(x, "foo bar");
1147 ok( x.className == "hi foo bar", "Check more added classes" );
1149 ok( x.className == "", "Remove all classes" );
1150 c.add(x, "hi foo bar");
1152 ok( x.className == "hi bar", "Check removal of one class" );
1153 ok( c.has(x, "hi"), "Check has1" );
1154 ok( c.has(x, "bar"), "Check has2" );
1157 test("remove()", function() {
1159 $("#ap").children().remove();
1160 ok( $("#ap").text().length > 10, "Check text is not removed" );
1161 ok( $("#ap").children().length == 0, "Check remove" );
1164 $("#ap").children().remove("a");
1165 ok( $("#ap").text().length > 10, "Check text is not removed" );
1166 ok( $("#ap").children().length == 1, "Check filtered remove" );
1169 test("empty()", function() {
1171 ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1172 ok( $("#ap").children().length == 4, "Check elements are not removed" );
1175 test("slice()", function() {
1177 isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1178 isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1179 isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1180 isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1182 isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1185 test("map()", function() {
1189 $("#ap").map(function(){
1190 return $(this).find("a").get();
1192 q("google", "groups", "anchor1", "mark"),
1197 $("#ap > a").map(function(){
1198 return this.parentNode;
1205 test("contents()", function() {
1207 equals( $("#ap").contents().length, 9, "Check element contents" );
1208 ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1209 var ibody = $("#loadediframe").contents()[0].body;
1210 ok( ibody, "Check existance of IFrame body" );
1212 equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1214 $(ibody).append("<div>init text</div>");
1215 equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1217 equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1219 $("div:last", ibody).text("div text");
1220 equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1222 $("div:last", ibody).remove();
1223 equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1225 equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1227 $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1228 $("table", ibody).remove();
1229 equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );