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(4 + (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();
430 element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
432 equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
434 element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
436 equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
439 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
442 var defaultText = 'Try them out:'
443 jQuery('<b>buga</b>').appendTo('#first');
444 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
445 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
448 var l = jQuery("#first").children().length + 2;
449 jQuery("<strong>test</strong>");
450 jQuery("<strong>test</strong>");
451 jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ])
453 equals( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
454 equals( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." );
457 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
458 jQuery(document.getElementById('first')).appendTo('#sap');
459 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
462 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
463 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
464 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
467 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
470 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
471 jQuery("#yahoo, #first").appendTo('#sap');
472 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
475 jQuery('#select1').appendTo('#foo');
476 t( 'Append select', '#foo select', ['select1'] );
479 var div = jQuery("<div/>").click(function(){
480 ok(true, "Running a cloned click.");
482 div.appendTo("#main, #moretests");
484 jQuery("#main div:last").click();
485 jQuery("#moretests div:last").click();
488 var div = jQuery("<div/>").appendTo("#main, #moretests");
490 equals( div.length, 2, "appendTo returns the inserted elements" );
492 div.addClass("test");
494 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
495 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
499 div = jQuery("<div/>");
500 jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
502 equals( div.children().length, 1, "Make sure the right number of children were inserted." );
504 div = jQuery("#moretests div");
506 var num = jQuery("#main div").length;
507 div.remove().appendTo("#main");
509 equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." );
514 var testPrepend = function(val) {
516 var defaultText = 'Try them out:'
517 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
518 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
519 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
522 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
523 jQuery('#sap').prepend(val( document.getElementById('first') ));
524 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
527 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
528 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
529 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
532 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
533 jQuery('#sap').prepend(val( jQuery("#yahoo, #first") ));
534 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
537 test("prepend(String|Element|Array<Element>|jQuery)", function() {
538 testPrepend(bareObj);
541 test("prepend(Function)", function() {
542 testPrepend(functionReturningObj);
545 test("prepend(Function) with incoming value", function() {
548 var defaultText = 'Try them out:', old = jQuery('#first').html();
549 var result = jQuery('#first').prepend(function(i, val) {
550 equals( val, old, "Make sure the incoming value is correct." );
551 return '<b>buga</b>';
553 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
555 old = jQuery("#select3").html();
557 equals( jQuery('#select3').prepend(function(i, val) {
558 equals( val, old, "Make sure the incoming value is correct." );
559 return '<option value="prependTest">Prepend Test</option>';
560 }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
563 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
564 old = jQuery('#sap').html();
566 jQuery('#sap').prepend(function(i, val) {
567 equals( val, old, "Make sure the incoming value is correct." );
568 return document.getElementById('first');
571 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
574 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
575 old = jQuery('#sap').html();
577 jQuery('#sap').prepend(function(i, val) {
578 equals( val, old, "Make sure the incoming value is correct." );
579 return [document.getElementById('first'), document.getElementById('yahoo')];
582 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
585 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
586 old = jQuery('#sap').html();
588 jQuery('#sap').prepend(function(i, val) {
589 equals( val, old, "Make sure the incoming value is correct." );
590 return jQuery("#yahoo, #first");
593 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
596 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
598 var defaultText = 'Try them out:'
599 jQuery('<b>buga</b>').prependTo('#first');
600 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
601 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
604 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
605 jQuery(document.getElementById('first')).prependTo('#sap');
606 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
609 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
610 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
611 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
614 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
615 jQuery("#yahoo, #first").prependTo('#sap');
616 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
619 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
620 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
622 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
625 var testBefore = function(val) {
627 var expected = 'This is a normal link: bugaYahoo';
628 jQuery('#yahoo').before(val( '<b>buga</b>' ));
629 equals( jQuery('#en').text(), expected, 'Insert String before' );
632 expected = "This is a normal link: Try them out:Yahoo";
633 jQuery('#yahoo').before(val( document.getElementById('first') ));
634 equals( jQuery('#en').text(), expected, "Insert element before" );
637 expected = "This is a normal link: Try them out:diveintomarkYahoo";
638 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
639 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
642 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
643 jQuery('#yahoo').before(val( jQuery("#mark, #first") ));
644 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
646 var set = jQuery("<div/>").before("<span>test</span>");
647 equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
648 equals( set.length, 2, "Insert the element before the disconnected node." );
651 test("before(String|Element|Array<Element>|jQuery)", function() {
655 test("before(Function)", function() {
656 testBefore(functionReturningObj);
659 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
661 var expected = 'This is a normal link: bugaYahoo';
662 jQuery('<b>buga</b>').insertBefore('#yahoo');
663 equals( jQuery('#en').text(), expected, 'Insert String before' );
666 expected = "This is a normal link: Try them out:Yahoo";
667 jQuery(document.getElementById('first')).insertBefore('#yahoo');
668 equals( jQuery('#en').text(), expected, "Insert element before" );
671 expected = "This is a normal link: Try them out:diveintomarkYahoo";
672 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
673 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
676 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
677 jQuery("#mark, #first").insertBefore('#yahoo');
678 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
681 var testAfter = function(val) {
683 var expected = 'This is a normal link: Yahoobuga';
684 jQuery('#yahoo').after(val( '<b>buga</b>' ));
685 equals( jQuery('#en').text(), expected, 'Insert String after' );
688 expected = "This is a normal link: YahooTry them out:";
689 jQuery('#yahoo').after(val( document.getElementById('first') ));
690 equals( jQuery('#en').text(), expected, "Insert element after" );
693 expected = "This is a normal link: YahooTry them out:diveintomark";
694 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
695 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
698 expected = "This is a normal link: YahoodiveintomarkTry them out:";
699 jQuery('#yahoo').after(val( jQuery("#mark, #first") ));
700 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
702 var set = jQuery("<div/>").after("<span>test</span>");
703 equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
704 equals( set.length, 2, "Insert the element after the disconnected node." );
707 test("after(String|Element|Array<Element>|jQuery)", function() {
711 test("after(Function)", function() {
712 testAfter(functionReturningObj);
715 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
717 var expected = 'This is a normal link: Yahoobuga';
718 jQuery('<b>buga</b>').insertAfter('#yahoo');
719 equals( jQuery('#en').text(), expected, 'Insert String after' );
722 expected = "This is a normal link: YahooTry them out:";
723 jQuery(document.getElementById('first')).insertAfter('#yahoo');
724 equals( jQuery('#en').text(), expected, "Insert element after" );
727 expected = "This is a normal link: YahooTry them out:diveintomark";
728 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
729 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
732 expected = "This is a normal link: YahoodiveintomarkTry them out:";
733 jQuery("#mark, #first").insertAfter('#yahoo');
734 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
737 var testReplaceWith = function(val) {
739 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
740 ok( jQuery("#replace")[0], 'Replace element with string' );
741 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
744 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
745 ok( jQuery("#first")[0], 'Replace element with element' );
746 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
749 jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
750 jQuery('#baz').replaceWith("Baz");
751 equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
752 ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
755 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
756 ok( jQuery("#first")[0], 'Replace element with array of elements' );
757 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
758 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
761 jQuery('#yahoo').replaceWith(val( jQuery("#mark, #first") ));
762 ok( jQuery("#first")[0], 'Replace element with set of elements' );
763 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
764 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
767 var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
768 var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
769 var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
771 y.replaceWith( tmp );
774 y.click(); // Shouldn't be run
775 child.click(); // Shouldn't be run
783 y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
784 var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
786 y.replaceWith( child2 );
795 var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
796 equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
797 equals( set.length, 1, "Replace the disconnected node." );
799 var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
800 // TODO: Work on jQuery(...) inline script execution
801 //$div.replaceWith("<div class='replacewith'></div><script>" +
802 //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
804 equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
805 jQuery('.replacewith').remove();
809 jQuery("#main").append("<div id='replaceWith'></div>");
810 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
812 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
813 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
815 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
816 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
819 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
820 testReplaceWith(bareObj);
823 test("replaceWith(Function)", function() {
824 testReplaceWith(functionReturningObj);
828 var y = jQuery("#yahoo")[0];
830 jQuery(y).replaceWith(function(){
831 equals( this, y, "Make sure the context is coming in correctly." );
837 test("replaceWith(string) for more than one element", function(){
840 equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed');
842 jQuery('#foo p').replaceWith('<span>bar</span>');
843 equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced');
844 equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced');
847 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
849 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
850 ok( jQuery("#replace")[0], 'Replace element with string' );
851 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
854 jQuery(document.getElementById('first')).replaceAll("#yahoo");
855 ok( jQuery("#first")[0], 'Replace element with element' );
856 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
859 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
860 ok( jQuery("#first")[0], 'Replace element with array of elements' );
861 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
862 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
865 jQuery("#mark, #first").replaceAll("#yahoo");
866 ok( jQuery("#first")[0], 'Replace element with set of elements' );
867 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
868 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
871 test("clone()", function() {
873 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
874 var clone = jQuery('#yahoo').clone();
875 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
876 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
879 "<table/>", "<tr/>", "<td/>", "<div/>",
880 "<button/>", "<ul/>", "<ol/>", "<li/>",
881 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
882 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
884 for (var i = 0; i < cloneTags.length; i++) {
885 var j = jQuery(cloneTags[i]);
886 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]);
889 // using contents will get comments regular, text, and comment nodes
890 var cl = jQuery("#nonnodes").contents().clone();
891 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
893 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
894 ok( true, "Bound event still exists." );
897 div = div.clone(true).clone(true);
898 equals( div.length, 1, "One element cloned" );
899 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
900 div.trigger("click");
902 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
903 div.find("table").click(function(){
904 ok( true, "Bound event still exists." );
907 div = div.clone(true);
908 equals( div.length, 1, "One element cloned" );
909 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
910 div.find("table:last").trigger("click");
912 // this is technically an invalid object, but because of the special
913 // classid instantiation it is the only kind that IE has trouble with,
914 // so let's test with it too.
915 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>');
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 // and here's a valid one.
923 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>');
925 clone = div.clone(true);
926 equals( clone.length, 1, "One element cloned" );
927 equals( clone.html(), div.html(), "Element contents cloned" );
928 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
930 div = jQuery("<div/>").data({ a: true });
931 var div2 = div.clone(true);
932 equals( div2.data("a"), true, "Data cloned." );
933 div2.data("a", false);
934 equals( div2.data("a"), false, "Ensure cloned element data object was correctly modified" );
935 equals( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" );
937 var form = document.createElement("form");
938 form.action = "/test/";
939 var div = document.createElement("div");
940 div.appendChild( document.createTextNode("test") );
941 form.appendChild( div );
943 equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
945 equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
949 test("clone() on XML nodes", function() {
952 jQuery.get("data/dashboard.xml", function (xml) {
953 var root = jQuery(xml.documentElement).clone();
954 var origTab = jQuery("tab", xml).eq(0);
955 var cloneTab = jQuery("tab", root).eq(0);
956 origTab.text("origval");
957 cloneTab.text("cloneval");
958 equals(origTab.text(), "origval", "Check original XML node was correctly set");
959 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
965 var testHtml = function(valueObj) {
968 jQuery.scriptorder = 0;
970 var div = jQuery("#main > div");
971 div.html(valueObj("<b>test</b>"));
973 for ( var i = 0; i < div.size(); i++ ) {
974 if ( div.get(i).childNodes.length != 1 ) pass = false;
976 ok( pass, "Set HTML" );
978 div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
980 equals( div.children().length, 2, "Make sure two child nodes exist." );
981 equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
983 var space = jQuery("<div/>").html(valueObj(" "))[0].innerHTML;
984 ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." );
985 equals( jQuery("<div/>").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." );
987 jQuery("#main").html(valueObj("<style>.foobar{color:green;}</style>"));
989 equals( jQuery("#main").children().length, 1, "Make sure there is a child element." );
990 equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
993 // using contents will get comments regular, text, and comment nodes
994 var j = jQuery("#nonnodes").contents();
995 j.html(valueObj("<b>bold</b>"));
997 // this is needed, or the expando added by jQuery unique will yield a different html
998 j.find('b').removeData();
999 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1001 jQuery("#main").html(valueObj("<select/>"));
1002 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
1003 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
1005 var $div = jQuery('<div />');
1006 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
1007 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
1009 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1010 equals( $div2.html(insert).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1011 equals( $div2.html("x" + insert).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1012 equals( $div2.html(" " + insert).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1014 var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
1016 equals( map[0].childNodes.length, 1, "The area was inserted." );
1017 equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
1021 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>'));
1023 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1024 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1025 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1027 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
1029 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>'));
1031 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>"));
1034 test("html(String)", function() {
1038 test("html(Function)", function() {
1039 testHtml(functionReturningObj);
1045 jQuery("#main").html(function(){
1046 return jQuery(this).text();
1049 ok( !/</.test( jQuery("#main").html() ), "Replace html with text." );
1050 ok( jQuery("#main").html().length > 0, "Make sure text exists." );
1053 test("html(Function) with incoming value", function() {
1056 var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
1058 div.html(function(i, val) {
1059 equals( val, old[i], "Make sure the incoming value is correct." );
1060 return "<b>test</b>";
1064 div.each(function(){
1065 if ( this.childNodes.length !== 1 ) {
1069 ok( pass, "Set HTML" );
1072 // using contents will get comments regular, text, and comment nodes
1073 var j = jQuery("#nonnodes").contents();
1074 old = j.map(function(){ return jQuery(this).html(); });
1076 j.html(function(i, val) {
1077 equals( val, old[i], "Make sure the incoming value is correct." );
1078 return "<b>bold</b>";
1081 // Handle the case where no comment is in the document
1082 if ( j.length === 2 ) {
1083 equals( null, null, "Make sure the incoming value is correct." );
1086 j.find('b').removeData();
1087 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1089 var $div = jQuery('<div />');
1091 equals( $div.html(function(i, val) {
1092 equals( val, "", "Make sure the incoming value is correct." );
1094 }).html(), '5', 'Setting a number as html' );
1096 equals( $div.html(function(i, val) {
1097 equals( val, "5", "Make sure the incoming value is correct." );
1099 }).html(), '0', 'Setting a zero as html' );
1101 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1102 equals( $div2.html(function(i, val) {
1103 equals( val, "", "Make sure the incoming value is correct." );
1105 }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1107 equals( $div2.html(function(i, val) {
1108 equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
1109 return "x" + insert;
1110 }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1112 equals( $div2.html(function(i, val) {
1113 equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
1114 return " " + insert;
1115 }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1118 var testRemove = function(method) {
1121 var first = jQuery("#ap").children(":first");
1122 first.data("foo", "bar");
1124 jQuery("#ap").children()[method]();
1125 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1126 equals( jQuery("#ap").children().length, 0, "Check remove" );
1128 equals( first.data("foo"), method == "remove" ? null : "bar" );
1131 jQuery("#ap").children()[method]("a");
1132 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1133 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1135 jQuery("#ap").children()[method]("a, code");
1136 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
1138 // using contents will get comments regular, text, and comment nodes
1139 // Handle the case where no comment is in the document
1140 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
1141 jQuery("#nonnodes").contents()[method]();
1142 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1147 var first = jQuery("#ap").children(":first");
1148 var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
1150 equals( method == "remove" ? 0 : 1, count );
1155 test("remove()", function() {
1156 testRemove("remove");
1159 test("detach()", function() {
1160 testRemove("detach");
1163 test("empty()", function() {
1165 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1166 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1168 // using contents will get comments regular, text, and comment nodes
1169 var j = jQuery("#nonnodes").contents();
1171 equals( j.html(), "", "Check node,textnode,comment empty works" );
1174 test("jQuery.cleanData", function() {
1177 var type, pos, div, child;
1181 // Should trigger 4 remove event
1182 div = getDiv().remove();
1184 // Should both do nothing
1186 div.trigger("click");
1189 div.children().trigger("click");
1193 child = div.children();
1195 // Should trigger 2 remove event
1200 div.trigger("click");
1202 // Should do nothing
1204 child.trigger("click");
1212 child = div.children();
1214 // Should trigger 2 remove event
1215 div.html("<div></div>");
1219 div.trigger("click");
1221 // Should do nothing
1223 child.trigger("click");
1229 var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
1230 ok( true, type + " " + pos + " Click event fired." );
1231 }).focus(function(){
1232 ok( true, type + " " + pos + " Focus event fired." );
1233 }).find("div").click(function(){
1234 ok( false, type + " " + pos + " Click event fired." );
1235 }).focus(function(){
1236 ok( false, type + " " + pos + " Focus event fired." );
1237 }).end().appendTo("body");
1239 div[0].detachEvent = div[0].removeEventListener = function(t){
1240 ok( true, type + " Outer " + t + " event unbound" );
1243 div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
1244 ok( true, type + " Inner " + t + " event unbound" );
1251 test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
1254 // DOM manipulation fails if added text matches an Object method
1255 var $f = jQuery( "<div />" ).appendTo( "#main" ),
1256 bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
1258 for ( var i=0; i < bad.length; i++ ) {
1260 $f.append( bad[i] );
1264 equals($f.text(), bad.join(''), "Cached strings that match Object properties");