1 module("manipulation");
3 // Ensure that an extended Array prototype doesn't break jQuery
4 Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); };
6 var bareObj = function(value) { return value; };
7 var functionReturningObj = function(value) { return (function() { return value; }); };
9 test("text()", function() {
11 var expected = "This link has class=\"blog\": Simon Willison's Weblog";
12 equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
14 // Check serialization of text values
15 equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
18 var testText = function(valueObj) {
20 var val = valueObj("<div><b>Hello</b> cruel world!</div>");
21 equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
23 // using contents will get comments regular, text, and comment nodes
24 var j = jQuery("#nonnodes").contents();
25 j.text(valueObj("hi!"));
26 equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
27 equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
29 // Blackberry 4.6 doesn't maintain comments in the DOM
30 equals( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" );
33 test("text(String)", function() {
37 test("text(Function)", function() {
38 testText(functionReturningObj);
41 test("text(Function) with incoming value", function() {
44 var old = "This link has class=\"blog\": Simon Willison's Weblog";
46 jQuery('#sap').text(function(i, val) {
47 equals( val, old, "Make sure the incoming value is correct." );
51 equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
56 var testWrap = function(val) {
58 var defaultText = 'Try them out:'
59 var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text();
60 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
61 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
64 var defaultText = 'Try them out:'
65 var result = jQuery('#first').wrap(val( document.getElementById('empty') )).parent();
66 ok( result.is('ol'), 'Check for element wrapping' );
67 equals( result.text(), defaultText, 'Check for element wrapping' );
70 jQuery('#check1').click(function() {
72 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
73 jQuery(checkbox).wrap(val( '<div id="c1" style="display:none;"></div>' ));
74 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
77 // using contents will get comments regular, text, and comment nodes
78 var j = jQuery("#nonnodes").contents();
79 j.wrap(val( "<i></i>" ));
81 // Blackberry 4.6 doesn't maintain comments in the DOM
82 equals( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[0].childNodes.length, "Check node,textnode,comment wraps ok" );
83 equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
85 // Try wrapping a disconnected node
87 for (var i in jQuery.cache) {
91 j = jQuery("<label/>").wrap(val( "<li/>" ));
92 equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
93 equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
95 for (i in jQuery.cache) {
98 equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
100 // Wrap an element containing a text node
101 j = jQuery("<span/>").wrap("<div>test</div>");
102 equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
103 equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
105 // Try to wrap an element with multiple elements (should fail)
106 j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
107 equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
108 equals( j.length, 1, "There should only be one element (no cloning)." );
109 equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
111 // Wrap an element with a jQuery set
112 j = jQuery("<span/>").wrap(jQuery("<div></div>"));
113 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
115 // Wrap an element with a jQuery set and event
116 result = jQuery("<div></div>").click(function(){
117 ok(true, "Event triggered.");
120 j = jQuery("<span/>").wrap(result);
121 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
123 j.parent().trigger("click");
126 test("wrap(String|Element)", function() {
130 test("wrap(Function)", function() {
131 testWrap(functionReturningObj);
134 var testWrapAll = function(val) {
136 var prev = jQuery("#firstp")[0].previousSibling;
137 var p = jQuery("#firstp,#first")[0].parentNode;
139 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
140 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
141 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
142 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
143 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
144 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
147 var prev = jQuery("#firstp")[0].previousSibling;
148 var p = jQuery("#first")[0].parentNode;
149 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
150 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
151 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
152 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
155 test("wrapAll(String|Element)", function() {
156 testWrapAll(bareObj);
159 var testWrapInner = function(val) {
161 var num = jQuery("#first").children().length;
162 var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
163 equals( jQuery("#first").children().length, 1, "Only one child" );
164 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
165 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
168 var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
169 var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
170 equals( jQuery("#first").children().length, 1, "Only one child" );
171 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
172 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
175 var num = jQuery("#first").children().length;
176 var result = jQuery('#first').wrapInner(val(document.getElementById('empty')));
177 equals( jQuery("#first").children().length, 1, "Only one child" );
178 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
179 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
181 var div = jQuery("<div/>");
182 div.wrapInner(val("<span></span>"));
183 equals(div.children().length, 1, "The contents were wrapped.");
184 equals(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
187 test("wrapInner(String|Element)", function() {
188 testWrapInner(bareObj);
191 test("wrapInner(Function)", function() {
192 testWrapInner(functionReturningObj)
195 test("unwrap()", function() {
198 jQuery("body").append(' <div id="unwrap" style="display: none;"> <div id="unwrap1"> <span class="unwrap">a</span> <span class="unwrap">b</span> </div> <div id="unwrap2"> <span class="unwrap">c</span> <span class="unwrap">d</span> </div> <div id="unwrap3"> <b><span class="unwrap unwrap3">e</span></b> <b><span class="unwrap unwrap3">f</span></b> </div> </div>');
200 var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(),
201 abcdef = jQuery('#unwrap span').get();
203 equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
204 same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' );
206 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' );
208 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' );
210 same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' );
212 same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' );
214 same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' );
215 same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' );
217 same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
219 jQuery('body > span.unwrap').remove();
222 var testAppend = function(valueObj) {
224 var defaultText = 'Try them out:'
225 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
226 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
227 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
230 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
231 jQuery('#sap').append(valueObj(document.getElementById('first')));
232 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
235 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
236 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
237 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
240 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
241 jQuery('#sap').append(valueObj(jQuery("#yahoo, #first")));
242 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
245 jQuery("#sap").append(valueObj( 5 ));
246 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
249 jQuery("#sap").append(valueObj( " text with spaces " ));
250 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
253 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
254 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
255 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
258 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />'));
259 jQuery("form input[name=radiotest]").each(function(){
260 ok( jQuery(this).is(':checked'), "Append checked radio");
264 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked = \'checked\' />'));
265 jQuery("form input[name=radiotest]").each(function(){
266 ok( jQuery(this).is(':checked'), "Append alternately formated checked radio");
270 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked />'));
271 jQuery("form input[name=radiotest]").each(function(){
272 ok( jQuery(this).is(':checked'), "Append HTML5-formated checked radio");
276 jQuery("#sap").append(valueObj( document.getElementById('form') ));
277 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
282 var body = jQuery("#iframe")[0].contentWindow.document.body;
285 jQuery( body ).append(valueObj( "<div>test</div>" ));
289 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
292 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
293 t( 'Append legend', '#legend', ['legend'] );
296 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
297 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
299 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
300 ok( jQuery('#table colgroup').length, "Append colgroup" );
302 jQuery('#table colgroup').append(valueObj( '<col/>' ));
303 ok( jQuery('#table colgroup col').length, "Append col" );
306 jQuery('#table').append(valueObj( '<caption></caption>' ));
307 ok( jQuery('#table caption').length, "Append caption" );
311 .append(valueObj( '<select id="appendSelect1"></select>' ))
312 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
314 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
316 equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
318 // using contents will get comments regular, text, and comment nodes
319 var j = jQuery("#nonnodes").contents();
320 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
321 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
322 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
323 d.contents().appendTo("#nonnodes");
325 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
328 test("append(String|Element|Array<Element>|jQuery)", function() {
332 test("append(Function)", function() {
333 testAppend(functionReturningObj);
336 test("append(Function) with incoming value", function() {
339 var defaultText = 'Try them out:', old = jQuery("#first").html();
341 var result = jQuery('#first').append(function(i, val){
342 equals( val, old, "Make sure the incoming value is correct." );
343 return '<b>buga</b>';
345 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
347 var select = jQuery('#select3');
350 equals( select.append(function(i, val){
351 equals( val, old, "Make sure the incoming value is correct." );
352 return '<option value="appendTest">Append Test</option>';
353 }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
356 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
357 old = jQuery("#sap").html();
359 jQuery('#sap').append(function(i, val){
360 equals( val, old, "Make sure the incoming value is correct." );
361 return document.getElementById('first');
363 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
366 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
367 old = jQuery("#sap").html();
369 jQuery('#sap').append(function(i, val){
370 equals( val, old, "Make sure the incoming value is correct." );
371 return [document.getElementById('first'), document.getElementById('yahoo')];
373 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
376 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
377 old = jQuery("#sap").html();
379 jQuery('#sap').append(function(i, val){
380 equals( val, old, "Make sure the incoming value is correct." );
381 return jQuery("#yahoo, #first");
383 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
386 old = jQuery("#sap").html();
388 jQuery("#sap").append(function(i, val){
389 equals( val, old, "Make sure the incoming value is correct." );
392 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
397 test("append the same fragment with events (Bug #6997, 5566)", function () {
398 expect(2 + (document.fireEvent ? 1 : 0));
403 // This patch modified the way that cloning occurs in IE; we need to make sure that
404 // native event handlers on the original object don't get disturbed when they are
405 // modified on the clone
406 if (!jQuery.support.noCloneEvent && document.fireEvent) {
407 element = jQuery("div:first").click(function () {
408 ok(true, "Event exists on original after being unbound on clone");
409 jQuery(this).unbind('click');
411 element.clone(true).unbind('click')[0].fireEvent('onclick');
412 element[0].fireEvent('onclick');
415 element = jQuery("<a class='test6997'></a>").click(function () {
416 ok(true, "Append second element events work");
419 jQuery("#listWithTabIndex li").append(element)
420 .find('a.test6997').eq(1).click();
422 element = jQuery("<li class='test6997'></li>").click(function () {
423 ok(true, "Before second element events work");
427 jQuery("#listWithTabIndex li").before(element);
428 jQuery("#listWithTabIndex li.test6997").eq(1).click();
431 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
434 var defaultText = 'Try them out:'
435 jQuery('<b>buga</b>').appendTo('#first');
436 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
437 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
440 var l = jQuery("#first").children().length + 2;
441 jQuery("<strong>test</strong>");
442 jQuery("<strong>test</strong>");
443 jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ])
445 equals( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
446 equals( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." );
449 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
450 jQuery(document.getElementById('first')).appendTo('#sap');
451 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
454 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
455 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
456 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
459 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
462 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
463 jQuery("#yahoo, #first").appendTo('#sap');
464 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
467 jQuery('#select1').appendTo('#foo');
468 t( 'Append select', '#foo select', ['select1'] );
471 var div = jQuery("<div/>").click(function(){
472 ok(true, "Running a cloned click.");
474 div.appendTo("#main, #moretests");
476 jQuery("#main div:last").click();
477 jQuery("#moretests div:last").click();
480 var div = jQuery("<div/>").appendTo("#main, #moretests");
482 equals( div.length, 2, "appendTo returns the inserted elements" );
484 div.addClass("test");
486 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
487 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
491 div = jQuery("<div/>");
492 jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
494 equals( div.children().length, 1, "Make sure the right number of children were inserted." );
496 div = jQuery("#moretests div");
498 var num = jQuery("#main div").length;
499 div.remove().appendTo("#main");
501 equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." );
506 var testPrepend = function(val) {
508 var defaultText = 'Try them out:'
509 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
510 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
511 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
514 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
515 jQuery('#sap').prepend(val( document.getElementById('first') ));
516 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
519 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
520 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
521 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
524 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
525 jQuery('#sap').prepend(val( jQuery("#yahoo, #first") ));
526 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
529 test("prepend(String|Element|Array<Element>|jQuery)", function() {
530 testPrepend(bareObj);
533 test("prepend(Function)", function() {
534 testPrepend(functionReturningObj);
537 test("prepend(Function) with incoming value", function() {
540 var defaultText = 'Try them out:', old = jQuery('#first').html();
541 var result = jQuery('#first').prepend(function(i, val) {
542 equals( val, old, "Make sure the incoming value is correct." );
543 return '<b>buga</b>';
545 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
547 old = jQuery("#select3").html();
549 equals( jQuery('#select3').prepend(function(i, val) {
550 equals( val, old, "Make sure the incoming value is correct." );
551 return '<option value="prependTest">Prepend Test</option>';
552 }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
555 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
556 old = jQuery('#sap').html();
558 jQuery('#sap').prepend(function(i, val) {
559 equals( val, old, "Make sure the incoming value is correct." );
560 return document.getElementById('first');
563 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
566 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
567 old = jQuery('#sap').html();
569 jQuery('#sap').prepend(function(i, val) {
570 equals( val, old, "Make sure the incoming value is correct." );
571 return [document.getElementById('first'), document.getElementById('yahoo')];
574 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
577 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
578 old = jQuery('#sap').html();
580 jQuery('#sap').prepend(function(i, val) {
581 equals( val, old, "Make sure the incoming value is correct." );
582 return jQuery("#yahoo, #first");
585 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
588 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
590 var defaultText = 'Try them out:'
591 jQuery('<b>buga</b>').prependTo('#first');
592 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
593 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
596 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
597 jQuery(document.getElementById('first')).prependTo('#sap');
598 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
601 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
602 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
603 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
606 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
607 jQuery("#yahoo, #first").prependTo('#sap');
608 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
611 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
612 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
614 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
617 var testBefore = function(val) {
619 var expected = 'This is a normal link: bugaYahoo';
620 jQuery('#yahoo').before(val( '<b>buga</b>' ));
621 equals( jQuery('#en').text(), expected, 'Insert String before' );
624 expected = "This is a normal link: Try them out:Yahoo";
625 jQuery('#yahoo').before(val( document.getElementById('first') ));
626 equals( jQuery('#en').text(), expected, "Insert element before" );
629 expected = "This is a normal link: Try them out:diveintomarkYahoo";
630 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
631 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
634 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
635 jQuery('#yahoo').before(val( jQuery("#mark, #first") ));
636 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
638 var set = jQuery("<div/>").before("<span>test</span>");
639 equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
640 equals( set.length, 2, "Insert the element before the disconnected node." );
643 test("before(String|Element|Array<Element>|jQuery)", function() {
647 test("before(Function)", function() {
648 testBefore(functionReturningObj);
651 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
653 var expected = 'This is a normal link: bugaYahoo';
654 jQuery('<b>buga</b>').insertBefore('#yahoo');
655 equals( jQuery('#en').text(), expected, 'Insert String before' );
658 expected = "This is a normal link: Try them out:Yahoo";
659 jQuery(document.getElementById('first')).insertBefore('#yahoo');
660 equals( jQuery('#en').text(), expected, "Insert element before" );
663 expected = "This is a normal link: Try them out:diveintomarkYahoo";
664 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
665 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
668 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
669 jQuery("#mark, #first").insertBefore('#yahoo');
670 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
673 var testAfter = function(val) {
675 var expected = 'This is a normal link: Yahoobuga';
676 jQuery('#yahoo').after(val( '<b>buga</b>' ));
677 equals( jQuery('#en').text(), expected, 'Insert String after' );
680 expected = "This is a normal link: YahooTry them out:";
681 jQuery('#yahoo').after(val( document.getElementById('first') ));
682 equals( jQuery('#en').text(), expected, "Insert element after" );
685 expected = "This is a normal link: YahooTry them out:diveintomark";
686 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
687 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
690 expected = "This is a normal link: YahoodiveintomarkTry them out:";
691 jQuery('#yahoo').after(val( jQuery("#mark, #first") ));
692 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
694 var set = jQuery("<div/>").after("<span>test</span>");
695 equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
696 equals( set.length, 2, "Insert the element after the disconnected node." );
699 test("after(String|Element|Array<Element>|jQuery)", function() {
703 test("after(Function)", function() {
704 testAfter(functionReturningObj);
707 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
709 var expected = 'This is a normal link: Yahoobuga';
710 jQuery('<b>buga</b>').insertAfter('#yahoo');
711 equals( jQuery('#en').text(), expected, 'Insert String after' );
714 expected = "This is a normal link: YahooTry them out:";
715 jQuery(document.getElementById('first')).insertAfter('#yahoo');
716 equals( jQuery('#en').text(), expected, "Insert element after" );
719 expected = "This is a normal link: YahooTry them out:diveintomark";
720 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
721 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
724 expected = "This is a normal link: YahoodiveintomarkTry them out:";
725 jQuery("#mark, #first").insertAfter('#yahoo');
726 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
729 var testReplaceWith = function(val) {
731 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
732 ok( jQuery("#replace")[0], 'Replace element with string' );
733 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
736 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
737 ok( jQuery("#first")[0], 'Replace element with element' );
738 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
741 jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
742 jQuery('#baz').replaceWith("Baz");
743 equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
744 ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
747 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
748 ok( jQuery("#first")[0], 'Replace element with array of elements' );
749 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
750 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
753 jQuery('#yahoo').replaceWith(val( jQuery("#mark, #first") ));
754 ok( jQuery("#first")[0], 'Replace element with set of elements' );
755 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
756 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
759 var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
760 var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
761 var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
763 y.replaceWith( tmp );
766 y.click(); // Shouldn't be run
767 child.click(); // Shouldn't be run
775 y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
776 var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
778 y.replaceWith( child2 );
787 var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
788 equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
789 equals( set.length, 1, "Replace the disconnected node." );
791 var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
792 // TODO: Work on jQuery(...) inline script execution
793 //$div.replaceWith("<div class='replacewith'></div><script>" +
794 //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
796 equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
797 jQuery('.replacewith').remove();
801 jQuery("#main").append("<div id='replaceWith'></div>");
802 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
804 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
805 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
807 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
808 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
811 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
812 testReplaceWith(bareObj);
815 test("replaceWith(Function)", function() {
816 testReplaceWith(functionReturningObj);
820 var y = jQuery("#yahoo")[0];
822 jQuery(y).replaceWith(function(){
823 equals( this, y, "Make sure the context is coming in correctly." );
829 test("replaceWith(string) for more than one element", function(){
832 equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed');
834 jQuery('#foo p').replaceWith('<span>bar</span>');
835 equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced');
836 equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced');
839 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
841 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
842 ok( jQuery("#replace")[0], 'Replace element with string' );
843 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
846 jQuery(document.getElementById('first')).replaceAll("#yahoo");
847 ok( jQuery("#first")[0], 'Replace element with element' );
848 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
851 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
852 ok( jQuery("#first")[0], 'Replace element with array of elements' );
853 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
854 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
857 jQuery("#mark, #first").replaceAll("#yahoo");
858 ok( jQuery("#first")[0], 'Replace element with set of elements' );
859 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
860 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
863 test("clone()", function() {
865 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
866 var clone = jQuery('#yahoo').clone();
867 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
868 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
871 "<table/>", "<tr/>", "<td/>", "<div/>",
872 "<button/>", "<ul/>", "<ol/>", "<li/>",
873 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
874 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
876 for (var i = 0; i < cloneTags.length; i++) {
877 var j = jQuery(cloneTags[i]);
878 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]);
881 // using contents will get comments regular, text, and comment nodes
882 var cl = jQuery("#nonnodes").contents().clone();
883 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
885 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
886 ok( true, "Bound event still exists." );
889 div = div.clone(true).clone(true);
890 equals( div.length, 1, "One element cloned" );
891 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
892 div.trigger("click");
894 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
895 div.find("table").click(function(){
896 ok( true, "Bound event still exists." );
899 div = div.clone(true);
900 equals( div.length, 1, "One element cloned" );
901 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
902 div.find("table:last").trigger("click");
904 // this is technically an invalid object, but because of the special
905 // classid instantiation it is the only kind that IE has trouble with,
906 // so let's test with it too.
907 div = jQuery("<div/>").html('<object height="355" width="425" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="movie" value="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="wmode" value="transparent"> </object>');
909 clone = div.clone(true);
910 equals( clone.length, 1, "One element cloned" );
911 equals( clone.html(), div.html(), "Element contents cloned" );
912 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
914 // and here's a valid one.
915 div = jQuery("<div/>").html('<object height="355" width="425" type="application/x-shockwave-flash" data="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="movie" value="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="wmode" value="transparent"> </object>');
917 clone = div.clone(true);
918 equals( clone.length, 1, "One element cloned" );
919 equals( clone.html(), div.html(), "Element contents cloned" );
920 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
922 div = jQuery("<div/>").data({ a: true });
923 var div2 = div.clone(true);
924 equals( div2.data("a"), true, "Data cloned." );
925 div2.data("a", false);
926 equals( div2.data("a"), false, "Ensure cloned element data object was correctly modified" );
927 equals( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
929 var form = document.createElement("form");
930 form.action = "/test/";
931 var div = document.createElement("div");
932 div.appendChild( document.createTextNode("test") );
933 form.appendChild( div );
935 equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
937 equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
940 test("clone(form element) (Bug #3879, #6655)", function() {
942 element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
944 equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
946 element = jQuery("<input type='checkbox' value='foo'>").attr('checked', 'checked');
947 clone = element.clone();
949 equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
950 equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
951 equals( clone[0].defaultChecked, !jQuery.support.noCloneEvent, "Checked input defaultChecked cloned correctly" );
953 element = jQuery("<input type='text' value='foo'>");
954 clone = element.clone();
955 equals( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" );
957 element = jQuery("<textarea>foo</textarea>");
958 clone = element.clone();
959 equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
963 test("clone() on XML nodes", function() {
966 jQuery.get("data/dashboard.xml", function (xml) {
967 var root = jQuery(xml.documentElement).clone();
968 var origTab = jQuery("tab", xml).eq(0);
969 var cloneTab = jQuery("tab", root).eq(0);
970 origTab.text("origval");
971 cloneTab.text("cloneval");
972 equals(origTab.text(), "origval", "Check original XML node was correctly set");
973 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
979 var testHtml = function(valueObj) {
982 jQuery.scriptorder = 0;
984 var div = jQuery("#main > div");
985 div.html(valueObj("<b>test</b>"));
987 for ( var i = 0; i < div.size(); i++ ) {
988 if ( div.get(i).childNodes.length != 1 ) pass = false;
990 ok( pass, "Set HTML" );
992 div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
994 equals( div.children().length, 2, "Make sure two child nodes exist." );
995 equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
997 var space = jQuery("<div/>").html(valueObj(" "))[0].innerHTML;
998 ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." );
999 equals( jQuery("<div/>").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." );
1001 jQuery("#main").html(valueObj("<style>.foobar{color:green;}</style>"));
1003 equals( jQuery("#main").children().length, 1, "Make sure there is a child element." );
1004 equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
1007 // using contents will get comments regular, text, and comment nodes
1008 var j = jQuery("#nonnodes").contents();
1009 j.html(valueObj("<b>bold</b>"));
1011 // this is needed, or the expando added by jQuery unique will yield a different html
1012 j.find('b').removeData();
1013 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1015 jQuery("#main").html(valueObj("<select/>"));
1016 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
1017 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
1019 var $div = jQuery('<div />');
1020 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
1021 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
1023 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1024 equals( $div2.html(insert).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1025 equals( $div2.html("x" + insert).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1026 equals( $div2.html(" " + insert).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1028 var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
1030 equals( map[0].childNodes.length, 1, "The area was inserted." );
1031 equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
1035 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>'));
1037 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1038 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1039 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1041 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
1043 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>'));
1045 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>"));
1048 test("html(String)", function() {
1052 test("html(Function)", function() {
1053 testHtml(functionReturningObj);
1059 jQuery("#main").html(function(){
1060 return jQuery(this).text();
1063 ok( !/</.test( jQuery("#main").html() ), "Replace html with text." );
1064 ok( jQuery("#main").html().length > 0, "Make sure text exists." );
1067 test("html(Function) with incoming value", function() {
1070 var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
1072 div.html(function(i, val) {
1073 equals( val, old[i], "Make sure the incoming value is correct." );
1074 return "<b>test</b>";
1078 div.each(function(){
1079 if ( this.childNodes.length !== 1 ) {
1083 ok( pass, "Set HTML" );
1086 // using contents will get comments regular, text, and comment nodes
1087 var j = jQuery("#nonnodes").contents();
1088 old = j.map(function(){ return jQuery(this).html(); });
1090 j.html(function(i, val) {
1091 equals( val, old[i], "Make sure the incoming value is correct." );
1092 return "<b>bold</b>";
1095 // Handle the case where no comment is in the document
1096 if ( j.length === 2 ) {
1097 equals( null, null, "Make sure the incoming value is correct." );
1100 j.find('b').removeData();
1101 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1103 var $div = jQuery('<div />');
1105 equals( $div.html(function(i, val) {
1106 equals( val, "", "Make sure the incoming value is correct." );
1108 }).html(), '5', 'Setting a number as html' );
1110 equals( $div.html(function(i, val) {
1111 equals( val, "5", "Make sure the incoming value is correct." );
1113 }).html(), '0', 'Setting a zero as html' );
1115 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1116 equals( $div2.html(function(i, val) {
1117 equals( val, "", "Make sure the incoming value is correct." );
1119 }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1121 equals( $div2.html(function(i, val) {
1122 equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
1123 return "x" + insert;
1124 }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1126 equals( $div2.html(function(i, val) {
1127 equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
1128 return " " + insert;
1129 }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1132 var testRemove = function(method) {
1135 var first = jQuery("#ap").children(":first");
1136 first.data("foo", "bar");
1138 jQuery("#ap").children()[method]();
1139 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1140 equals( jQuery("#ap").children().length, 0, "Check remove" );
1142 equals( first.data("foo"), method == "remove" ? null : "bar" );
1145 jQuery("#ap").children()[method]("a");
1146 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1147 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1149 jQuery("#ap").children()[method]("a, code");
1150 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
1152 // using contents will get comments regular, text, and comment nodes
1153 // Handle the case where no comment is in the document
1154 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
1155 jQuery("#nonnodes").contents()[method]();
1156 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1161 var first = jQuery("#ap").children(":first");
1162 var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
1164 equals( method == "remove" ? 0 : 1, count );
1169 test("remove()", function() {
1170 testRemove("remove");
1173 test("detach()", function() {
1174 testRemove("detach");
1177 test("empty()", function() {
1179 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1180 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1182 // using contents will get comments regular, text, and comment nodes
1183 var j = jQuery("#nonnodes").contents();
1185 equals( j.html(), "", "Check node,textnode,comment empty works" );
1188 test("jQuery.cleanData", function() {
1191 var type, pos, div, child;
1195 // Should trigger 4 remove event
1196 div = getDiv().remove();
1198 // Should both do nothing
1200 div.trigger("click");
1203 div.children().trigger("click");
1207 child = div.children();
1209 // Should trigger 2 remove event
1214 div.trigger("click");
1216 // Should do nothing
1218 child.trigger("click");
1226 child = div.children();
1228 // Should trigger 2 remove event
1229 div.html("<div></div>");
1233 div.trigger("click");
1235 // Should do nothing
1237 child.trigger("click");
1243 var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
1244 ok( true, type + " " + pos + " Click event fired." );
1245 }).focus(function(){
1246 ok( true, type + " " + pos + " Focus event fired." );
1247 }).find("div").click(function(){
1248 ok( false, type + " " + pos + " Click event fired." );
1249 }).focus(function(){
1250 ok( false, type + " " + pos + " Focus event fired." );
1251 }).end().appendTo("body");
1253 div[0].detachEvent = div[0].removeEventListener = function(t){
1254 ok( true, type + " Outer " + t + " event unbound" );
1257 div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
1258 ok( true, type + " Inner " + t + " event unbound" );
1265 test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
1268 // DOM manipulation fails if added text matches an Object method
1269 var $f = jQuery( "<div />" ).appendTo( "#main" ),
1270 bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
1272 for ( var i=0; i < bad.length; i++ ) {
1274 $f.append( bad[i] );
1278 equals($f.text(), bad.join(''), "Cached strings that match Object properties");