Make sure the fragment isn't used if it's not the same set we're working with. Fixes...
[jquery.git] / test / unit / manipulation.js
1 module("manipulation");
2
3 var bareObj = function(value) { return value; };
4 var functionReturningObj = function(value) { return (function() { return value; }); };
5
6 test("text()", function() {
7         expect(2);
8         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
9         equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
10
11         // Check serialization of text values
12         equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
13 });
14
15 var testText = function(valueObj) {
16         expect(4);
17         var val = valueObj("<div><b>Hello</b> cruel world!</div>");
18         equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
19
20         // using contents will get comments regular, text, and comment nodes
21         var j = jQuery("#nonnodes").contents();
22         j.text(valueObj("hi!"));
23         equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
24         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
25         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
26 }
27
28 test("text(String)", function() {
29         testText(bareObj)
30 });
31
32 test("text(Function)", function() {
33         testText(functionReturningObj);
34 });
35
36 test("text(Function) with incoming value", function() {
37         expect(2);
38         
39         var old = "This link has class=\"blog\": Simon Willison's Weblog";
40         
41         jQuery('#sap').text(function(i, val) {
42                 equals( val, old, "Make sure the incoming value is correct." );
43                 return "foobar";
44         });
45         
46         equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
47         
48         reset();
49 });
50
51 var testWrap = function(val) {
52         expect(18);
53         var defaultText = 'Try them out:'
54         var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text();
55         equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
56         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
57
58         reset();
59         var defaultText = 'Try them out:'
60         var result = jQuery('#first').wrap(val( document.getElementById('empty') )).parent();
61         ok( result.is('ol'), 'Check for element wrapping' );
62         equals( result.text(), defaultText, 'Check for element wrapping' );
63
64         reset();
65         jQuery('#check1').click(function() {
66                 var checkbox = this;
67                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
68                 jQuery(checkbox).wrap(val( '<div id="c1" style="display:none;"></div>' ));
69                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
70         }).click();
71
72         // using contents will get comments regular, text, and comment nodes
73         var j = jQuery("#nonnodes").contents();
74         j.wrap(val( "<i></i>" ));
75         equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
76         equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
77
78         // Try wrapping a disconnected node
79         j = jQuery("<label/>").wrap(val( "<li/>" ));
80         equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
81         equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
82
83         // Wrap an element containing a text node
84         j = jQuery("<span/>").wrap("<div>test</div>");
85         equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
86         equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
87
88         // Try to wrap an element with multiple elements (should fail)
89         j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
90         equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
91         equals( j.length, 1, "There should only be one element (no cloning)." );
92         equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
93
94         // Wrap an element with a jQuery set
95         j = jQuery("<span/>").wrap(jQuery("<div></div>"));
96         equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
97
98         // Wrap an element with a jQuery set and event
99         result = jQuery("<div></div>").click(function(){
100                 ok(true, "Event triggered.");
101         });
102
103         j = jQuery("<span/>").wrap(result);
104         equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
105
106         j.parent().trigger("click");
107 }
108
109 test("wrap(String|Element)", function() {
110         testWrap(bareObj);
111 });
112
113 test("wrap(Function)", function() {
114         testWrap(functionReturningObj);
115 })
116
117 var testWrapAll = function(val) {
118         expect(8);
119         var prev = jQuery("#firstp")[0].previousSibling;
120         var p = jQuery("#firstp,#first")[0].parentNode;
121
122         var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
123         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
124         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
125         ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
126         equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
127         equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
128
129         reset();
130         var prev = jQuery("#firstp")[0].previousSibling;
131         var p = jQuery("#first")[0].parentNode;
132         var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
133         equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
134         equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
135         equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
136 }
137
138 test("wrapAll(String|Element)", function() {
139         testWrapAll(bareObj);
140 });
141
142 var testWrapInner = function(val) {
143         expect(11);
144         var num = jQuery("#first").children().length;
145         var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
146         equals( jQuery("#first").children().length, 1, "Only one child" );
147         ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
148         equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
149
150         reset();
151         var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
152         var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
153         equals( jQuery("#first").children().length, 1, "Only one child" );
154         ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
155         equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
156
157         reset();
158         var num = jQuery("#first").children().length;
159         var result = jQuery('#first').wrapInner(val(document.getElementById('empty')));
160         equals( jQuery("#first").children().length, 1, "Only one child" );
161         ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
162         equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
163
164         var div = jQuery("<div/>");
165         div.wrapInner(val("<span></span>"));
166         equals(div.children().length, 1, "The contents were wrapped.");
167         equals(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
168 }
169
170 test("wrapInner(String|Element)", function() {
171         testWrapInner(bareObj);
172 });
173
174 test("wrapInner(Function)", function() {
175         testWrapInner(functionReturningObj)
176 });
177
178 test("unwrap()", function() {
179         expect(9);
180
181         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>');
182
183         var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(),
184                 abcdef = jQuery('#unwrap span').get();
185
186         equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
187         same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' );
188
189         same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' );
190
191         same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' );
192
193         same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' );
194
195         same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' );
196
197         same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' );
198         same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' );
199
200         same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
201
202         jQuery('body > span.unwrap').remove();
203 });
204
205 var testAppend = function(valueObj) {
206         expect(37);
207         var defaultText = 'Try them out:'
208         var result = jQuery('#first').append(valueObj('<b>buga</b>'));
209         equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
210         equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
211
212         reset();
213         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
214         jQuery('#sap').append(valueObj(document.getElementById('first')));
215         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
216
217         reset();
218         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
219         jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
220         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
221
222         reset();
223         expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
224         jQuery('#sap').append(valueObj(jQuery("#first, #yahoo")));
225         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
226
227         reset();
228         jQuery("#sap").append(valueObj( 5 ));
229         ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
230
231         reset();
232         jQuery("#sap").append(valueObj( " text with spaces " ));
233         ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
234
235         reset();
236         ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
237         ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
238         ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
239         
240         reset();
241         jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />'));
242         jQuery("form input[name=radiotest]").each(function(){
243                 ok( jQuery(this).is(':checked'), "Append checked radio");
244         }).remove();
245
246         reset();
247         jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked    =   \'checked\' />'));
248         jQuery("form input[name=radiotest]").each(function(){
249                 ok( jQuery(this).is(':checked'), "Append alternately formated checked radio");
250         }).remove();
251
252         reset();
253         jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked />'));
254         jQuery("form input[name=radiotest]").each(function(){
255                 ok( jQuery(this).is(':checked'), "Append HTML5-formated checked radio");
256         }).remove();
257
258         reset();
259         jQuery("#sap").append(valueObj( document.getElementById('form') ));
260         equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
261
262         reset();
263         var pass = true;
264         try {
265                 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append(valueObj( "<div>test</div>" ));
266         } catch(e) {
267                 pass = false;
268         }
269
270         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
271
272         reset();
273         jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
274         t( 'Append legend', '#legend', ['legend'] );
275
276         reset();
277         jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
278         equals( jQuery('#select1 option:last').text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
279
280         jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
281         ok( jQuery('#table colgroup').length, "Append colgroup" );
282
283         jQuery('#table colgroup').append(valueObj( '<col/>' ));
284         ok( jQuery('#table colgroup col').length, "Append col" );
285
286         reset();
287         jQuery('#table').append(valueObj( '<caption></caption>' ));
288         ok( jQuery('#table caption').length, "Append caption" );
289
290         reset();
291         jQuery('form:last')
292                 .append(valueObj( '<select id="appendSelect1"></select>' ))
293                 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
294
295         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
296
297         equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
298
299         // using contents will get comments regular, text, and comment nodes
300         var j = jQuery("#nonnodes").contents();
301         var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
302         equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
303         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
304         d.contents().appendTo("#nonnodes");
305         d.remove();
306         ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
307 }
308
309 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
310         testAppend(bareObj);
311 });
312
313 test("append(Function)", function() {
314         testAppend(functionReturningObj);
315 });
316
317 test("append(Function) with incoming value", function() {
318         expect(12);
319         
320         var defaultText = 'Try them out:', old = jQuery("#first").html();
321         
322         var result = jQuery('#first').append(function(i, val){
323                 equals( val, old, "Make sure the incoming value is correct." );
324                 return '<b>buga</b>';
325         });
326         equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
327         
328         var select = jQuery('#select3');
329         old = select.html();
330         
331         equals( select.append(function(i, val){
332                 equals( val, old, "Make sure the incoming value is correct." );
333                 return '<option value="appendTest">Append Test</option>';
334         }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
335
336         reset();
337         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
338         old = jQuery("#sap").html();
339         
340         jQuery('#sap').append(function(i, val){
341                 equals( val, old, "Make sure the incoming value is correct." );
342                 return document.getElementById('first');
343         });
344         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
345
346         reset();
347         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
348         old = jQuery("#sap").html();
349         
350         jQuery('#sap').append(function(i, val){
351                 equals( val, old, "Make sure the incoming value is correct." );
352                 return [document.getElementById('first'), document.getElementById('yahoo')];
353         });
354         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
355
356         reset();
357         expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
358         old = jQuery("#sap").html();
359         
360         jQuery('#sap').append(function(i, val){
361                 equals( val, old, "Make sure the incoming value is correct." );
362                 return jQuery("#first, #yahoo");
363         });
364         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
365
366         reset();
367         old = jQuery("#sap").html();
368         
369         jQuery("#sap").append(function(i, val){
370                 equals( val, old, "Make sure the incoming value is correct." );
371                 return 5;
372         });
373         ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );        
374         
375         reset();
376 });
377
378 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
379         expect(13);
380         var defaultText = 'Try them out:'
381         jQuery('<b>buga</b>').appendTo('#first');
382         equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
383         equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
384
385         reset();
386         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
387         jQuery(document.getElementById('first')).appendTo('#sap');
388         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
389
390         reset();
391         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
392         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
393         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
394
395         reset();
396         ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
397
398         reset();
399         expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
400         jQuery("#first, #yahoo").appendTo('#sap');
401         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
402
403         reset();
404         jQuery('#select1').appendTo('#foo');
405         t( 'Append select', '#foo select', ['select1'] );
406
407         reset();
408         var div = jQuery("<div/>").click(function(){
409                 ok(true, "Running a cloned click.");
410         });
411         div.appendTo("#main, #moretests");
412
413         jQuery("#main div:last").click();
414         jQuery("#moretests div:last").click();
415
416         reset();
417         var div = jQuery("<div/>").appendTo("#main, #moretests");
418
419         equals( div.length, 2, "appendTo returns the inserted elements" );
420
421         div.addClass("test");
422
423         ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
424         ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
425
426         reset();
427
428         div = jQuery("<div/>");
429         jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
430
431         equals( div.children().length, 1, "Make sure the right number of children were inserted." );
432 });
433
434 var testPrepend = function(val) {
435         expect(5);
436         var defaultText = 'Try them out:'
437         var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
438         equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
439         equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
440
441         reset();
442         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
443         jQuery('#sap').prepend(val( document.getElementById('first') ));
444         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
445
446         reset();
447         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
448         jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
449         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
450
451         reset();
452         expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
453         jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
454         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
455 };
456
457 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
458         testPrepend(bareObj);
459 });
460
461 test("prepend(Function)", function() {
462         testPrepend(functionReturningObj);
463 });
464
465 test("prepend(Function) with incoming value", function() {
466         expect(10);
467         
468         var defaultText = 'Try them out:', old = jQuery('#first').html();
469         var result = jQuery('#first').prepend(function(i, val) {
470                 equals( val, old, "Make sure the incoming value is correct." );
471                 return '<b>buga</b>';
472         });
473         equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
474         
475         old = jQuery("#select3").html();
476         
477         equals( jQuery('#select3').prepend(function(i, val) {
478                 equals( val, old, "Make sure the incoming value is correct." );
479                 return '<option value="prependTest">Prepend Test</option>';
480         }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
481
482         reset();
483         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
484         old = jQuery('#sap').html();
485         
486         jQuery('#sap').prepend(function(i, val) {
487                 equals( val, old, "Make sure the incoming value is correct." );
488                 return document.getElementById('first');
489         });
490         
491         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
492
493         reset();
494         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
495         old = jQuery('#sap').html();
496         
497         jQuery('#sap').prepend(function(i, val) {
498                 equals( val, old, "Make sure the incoming value is correct." );
499                 return [document.getElementById('first'), document.getElementById('yahoo')];
500         });
501         
502         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
503
504         reset();
505         expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
506         old = jQuery('#sap').html();
507         
508         jQuery('#sap').prepend(function(i, val) {
509                 equals( val, old, "Make sure the incoming value is correct." );
510                 return jQuery("#first, #yahoo");
511         });
512         
513         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );     
514 });
515
516 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
517         expect(6);
518         var defaultText = 'Try them out:'
519         jQuery('<b>buga</b>').prependTo('#first');
520         equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
521         equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
522
523         reset();
524         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
525         jQuery(document.getElementById('first')).prependTo('#sap');
526         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
527
528         reset();
529         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
530         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
531         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
532
533         reset();
534         expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
535         jQuery("#first, #yahoo").prependTo('#sap');
536         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
537
538         reset();
539         jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
540         jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
541
542         t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
543 });
544
545 var testBefore = function(val) {
546         expect(6);
547         var expected = 'This is a normal link: bugaYahoo';
548         jQuery('#yahoo').before(val( '<b>buga</b>' ));
549         equals( expected, jQuery('#en').text(), 'Insert String before' );
550
551         reset();
552         expected = "This is a normal link: Try them out:Yahoo";
553         jQuery('#yahoo').before(val( document.getElementById('first') ));
554         equals( expected, jQuery('#en').text(), "Insert element before" );
555
556         reset();
557         expected = "This is a normal link: Try them out:diveintomarkYahoo";
558         jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
559         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
560
561         reset();
562         expected = "This is a normal link: diveintomarkTry them out:Yahoo";
563         jQuery('#yahoo').before(val( jQuery("#first, #mark") ));
564         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
565
566         var set = jQuery("<div/>").before("<span>test</span>");
567         equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
568         equals( set.length, 2, "Insert the element before the disconnected node." );
569 }
570
571 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
572         testBefore(bareObj);
573 });
574
575 test("before(Function)", function() {
576         testBefore(functionReturningObj);
577 })
578
579 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
580         expect(4);
581         var expected = 'This is a normal link: bugaYahoo';
582         jQuery('<b>buga</b>').insertBefore('#yahoo');
583         equals( expected, jQuery('#en').text(), 'Insert String before' );
584
585         reset();
586         expected = "This is a normal link: Try them out:Yahoo";
587         jQuery(document.getElementById('first')).insertBefore('#yahoo');
588         equals( expected, jQuery('#en').text(), "Insert element before" );
589
590         reset();
591         expected = "This is a normal link: Try them out:diveintomarkYahoo";
592         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
593         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
594
595         reset();
596         expected = "This is a normal link: diveintomarkTry them out:Yahoo";
597         jQuery("#first, #mark").insertBefore('#yahoo');
598         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
599 });
600
601 var testAfter = function(val) {
602         expect(6);
603         var expected = 'This is a normal link: Yahoobuga';
604         jQuery('#yahoo').after(val( '<b>buga</b>' ));
605         equals( expected, jQuery('#en').text(), 'Insert String after' );
606
607         reset();
608         expected = "This is a normal link: YahooTry them out:";
609         jQuery('#yahoo').after(val( document.getElementById('first') ));
610         equals( expected, jQuery('#en').text(), "Insert element after" );
611
612         reset();
613         expected = "This is a normal link: YahooTry them out:diveintomark";
614         jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
615         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
616
617         reset();
618         expected = "This is a normal link: YahoodiveintomarkTry them out:";
619         jQuery('#yahoo').after(val( jQuery("#first, #mark") ));
620         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
621
622         var set = jQuery("<div/>").after("<span>test</span>");
623         equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
624         equals( set.length, 2, "Insert the element after the disconnected node." );
625 };
626
627 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
628         testAfter(bareObj);
629 });
630
631 test("after(Function)", function() {
632         testAfter(functionReturningObj);
633 })
634
635 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
636         expect(4);
637         var expected = 'This is a normal link: Yahoobuga';
638         jQuery('<b>buga</b>').insertAfter('#yahoo');
639         equals( expected, jQuery('#en').text(), 'Insert String after' );
640
641         reset();
642         expected = "This is a normal link: YahooTry them out:";
643         jQuery(document.getElementById('first')).insertAfter('#yahoo');
644         equals( expected, jQuery('#en').text(), "Insert element after" );
645
646         reset();
647         expected = "This is a normal link: YahooTry them out:diveintomark";
648         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
649         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
650
651         reset();
652         expected = "This is a normal link: YahoodiveintomarkTry them out:";
653         jQuery("#first, #mark").insertAfter('#yahoo');
654         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
655 });
656
657 var testReplaceWith = function(val) {
658         expect(17);
659         jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
660         ok( jQuery("#replace")[0], 'Replace element with string' );
661         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
662
663         reset();
664         jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
665         ok( jQuery("#first")[0], 'Replace element with element' );
666         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
667
668         reset();
669         jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
670         jQuery('#baz').replaceWith("Baz");
671         equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
672         ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
673
674         reset();
675         jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
676         ok( jQuery("#first")[0], 'Replace element with array of elements' );
677         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
678         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
679
680         reset();
681         jQuery('#yahoo').replaceWith(val( jQuery("#first, #mark") ));
682         ok( jQuery("#first")[0], 'Replace element with set of elements' );
683         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
684         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
685
686         reset();
687         var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
688         var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
689         var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
690
691         y.replaceWith( tmp );
692
693         tmp.click();
694         y.click(); // Shouldn't be run
695         child.click(); // Shouldn't be run
696
697         tmp.remove();
698         y.remove();
699         child.remove();
700
701         reset();
702
703         y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
704         var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
705
706         y.replaceWith( child2 );
707
708         child2.click();
709
710         y.remove();
711         child2.remove();
712
713         reset();
714
715         var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
716         equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
717         equals( set.length, 1, "Replace the disconnected node." );
718
719         var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
720         // TODO: Work on jQuery(...) inline script execution
721         //$div.replaceWith("<div class='replacewith'></div><script>" +
722                 //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
723                 //"</script>");
724         equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
725         jQuery('.replacewith').remove();
726 }
727
728 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
729         testReplaceWith(bareObj);
730 });
731
732 test("replaceWith(Function)", function() {
733         testReplaceWith(functionReturningObj);
734
735         expect(18);
736
737         var y = jQuery("#yahoo")[0];
738
739         jQuery(y).replaceWith(function(){
740                 equals( this, y, "Make sure the context is coming in correctly." );
741         });
742
743         reset();
744 });
745
746 test("replaceWith(string) for more than one element", function(){
747         expect(3);
748
749         equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed');
750
751         jQuery('#foo p').replaceWith('<span>bar</span>');
752         equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced');
753         equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced');
754 });
755
756 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
757         expect(10);
758         jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
759         ok( jQuery("#replace")[0], 'Replace element with string' );
760         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
761
762         reset();
763         jQuery(document.getElementById('first')).replaceAll("#yahoo");
764         ok( jQuery("#first")[0], 'Replace element with element' );
765         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
766
767         reset();
768         jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
769         ok( jQuery("#first")[0], 'Replace element with array of elements' );
770         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
771         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
772
773         reset();
774         jQuery("#first, #mark").replaceAll("#yahoo");
775         ok( jQuery("#first")[0], 'Replace element with set of elements' );
776         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
777         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
778 });
779
780 test("clone()", function() {
781         expect(31);
782         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
783         var clone = jQuery('#yahoo').clone();
784         equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
785         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
786
787         var cloneTags = [
788                 "<table/>", "<tr/>", "<td/>", "<div/>",
789                 "<button/>", "<ul/>", "<ol/>", "<li/>",
790                 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
791                 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
792         ];
793         for (var i = 0; i < cloneTags.length; i++) {
794                 var j = jQuery(cloneTags[i]);
795                 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
796         }
797
798         // using contents will get comments regular, text, and comment nodes
799         var cl = jQuery("#nonnodes").contents().clone();
800         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
801
802         var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
803                 ok( true, "Bound event still exists." );
804         });
805
806         div = div.clone(true).clone(true);
807         equals( div.length, 1, "One element cloned" );
808         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
809         div.trigger("click");
810
811         div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
812         div.find("table").click(function(){
813                 ok( true, "Bound event still exists." );
814         });
815
816         div = div.clone(true);
817         equals( div.length, 1, "One element cloned" );
818         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
819         div.find("table:last").trigger("click");
820
821         div = jQuery("<div/>").html('<object height="355" width="425">  <param name="movie" value="http://www.youtube.com/v/JikaHBDoV3k&amp;hl=en">  <param name="wmode" value="transparent"> </object>');
822
823         div = div.clone(true);
824         equals( div.length, 1, "One element cloned" );
825         equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
826
827         div = jQuery("<div/>").data({ a: true, b: true });
828         div = div.clone(true);
829         equals( div.data("a"), true, "Data cloned." );
830         equals( div.data("b"), true, "Data cloned." );
831
832         var form = document.createElement("form");
833         form.action = "/test/";
834         var div = document.createElement("div");
835         div.appendChild( document.createTextNode("test") );
836         form.appendChild( div );
837
838         equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
839 });
840
841 if (!isLocal) {
842 test("clone() on XML nodes", function() {
843         expect(2);
844         stop();
845         jQuery.get("data/dashboard.xml", function (xml) {
846                 var root = jQuery(xml.documentElement).clone();
847                 var origTab = jQuery("tab", xml).eq(0);
848                 var cloneTab = jQuery("tab", root).eq(0);
849                 origTab.text("origval");
850                 cloneTab.text("cloneval");
851                 equals(origTab.text(), "origval", "Check original XML node was correctly set");
852                 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
853                 start();
854         });
855 });
856 }
857
858 var testHtml = function(valueObj) {
859         expect(26);
860
861         jQuery.scriptorder = 0;
862
863         var div = jQuery("#main > div");
864         div.html(valueObj("<b>test</b>"));
865         var pass = true;
866         for ( var i = 0; i < div.size(); i++ ) {
867                 if ( div.get(i).childNodes.length != 1 ) pass = false;
868         }
869         ok( pass, "Set HTML" );
870
871         div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
872
873         equals( div.children().length, 2, "Make sure two child nodes exist." );
874         equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
875
876         equals( jQuery("<div/>").html(valueObj("&#160;"))[0].innerHTML, "&nbsp;", "Make sure entities are passed through correctly." );
877         equals( jQuery("<div/>").html(valueObj("&amp;"))[0].innerHTML, "&amp;", "Make sure entities are passed through correctly." );
878
879         reset();
880         // using contents will get comments regular, text, and comment nodes
881         var j = jQuery("#nonnodes").contents();
882         j.html(valueObj("<b>bold</b>"));
883
884         // this is needed, or the expando added by jQuery unique will yield a different html
885         j.find('b').removeData();
886         equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
887
888         jQuery("#main").html(valueObj("<select/>"));
889         jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
890         equals( jQuery("#main select").val(), "O2", "Selected option correct" );
891
892         var $div = jQuery('<div />');
893         equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
894         equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
895
896         var $div2 = jQuery('<div/>'), insert = "&lt;div&gt;hello1&lt;/div&gt;";
897         equals( $div2.html(insert).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
898         equals( $div2.html("x" + insert).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." );
899         equals( $div2.html(" " + insert).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." );
900
901         var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
902
903         equals( map[0].childNodes.length, 1, "The area was inserted." );
904         equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
905
906         reset();
907
908         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>'));
909
910         stop();
911
912         jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
913
914         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>'));
915
916         // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
917         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>"));
918
919         setTimeout( start, 100 );
920 }
921
922 test("html(String)", function() {
923         testHtml(bareObj);
924 });
925
926 test("html(Function)", function() {
927         testHtml(functionReturningObj);
928 });
929
930 test("html(Function) with incoming value", function() {
931         expect(20);
932         
933         var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
934         
935         div.html(function(i, val) {
936                 equals( val, old[i], "Make sure the incoming value is correct." );
937                 return "<b>test</b>";
938         });
939         
940         var pass = true;
941         div.each(function(){
942                 if ( this.childNodes.length !== 1 ) {
943                         pass = false;
944                 }
945         })
946         ok( pass, "Set HTML" );
947
948         reset();
949         // using contents will get comments regular, text, and comment nodes
950         var j = jQuery("#nonnodes").contents();
951         old = j.map(function(){ return jQuery(this).html(); });
952         
953         j.html(function(i, val) {
954                 equals( val, old[i], "Make sure the incoming value is correct." );
955                 return "<b>bold</b>";
956         });
957         
958         j.find('b').removeData();
959         equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
960         
961         var $div = jQuery('<div />');
962         
963         equals( $div.html(function(i, val) {
964                 equals( val, "", "Make sure the incoming value is correct." );
965                 return 5;
966         }).html(), '5', 'Setting a number as html' );
967         
968         equals( $div.html(function(i, val) {
969                 equals( val, "5", "Make sure the incoming value is correct." );
970                 return 0;
971         }).html(), '0', 'Setting a zero as html' );
972
973         var $div2 = jQuery('<div/>'), insert = "&lt;div&gt;hello1&lt;/div&gt;";
974         equals( $div2.html(function(i, val) {
975                 equals( val, "", "Make sure the incoming value is correct." );
976                 return insert;
977         }).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
978         
979         equals( $div2.html(function(i, val) {
980                 equals( val.replace(/>/g, "&gt;"), insert, "Make sure the incoming value is correct." );
981                 return "x" + insert;
982         }).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." );
983         
984         equals( $div2.html(function(i, val) {
985                 equals( val.replace(/>/g, "&gt;"), "x" + insert, "Make sure the incoming value is correct." );
986                 return " " + insert;
987         }).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." );   
988 });
989
990 var testRemove = function(method) {
991         expect(9);
992
993         var first = jQuery("#ap").children(":first");
994         first.data("foo", "bar");
995
996         jQuery("#ap").children()[method]();
997         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
998         equals( jQuery("#ap").children().length, 0, "Check remove" );
999
1000         equals( first.data("foo"), method == "remove" ? null : "bar" );
1001
1002         reset();
1003         jQuery("#ap").children()[method]("a");
1004         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1005         equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1006
1007         jQuery("#ap").children()[method]("a, code");
1008         equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
1009
1010         // using contents will get comments regular, text, and comment nodes
1011         equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1012         jQuery("#nonnodes").contents()[method]();
1013         equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1014
1015         reset();
1016
1017         var count = 0;
1018         var first = jQuery("#ap").children(":first");
1019         var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
1020         
1021         equals( method == "remove" ? 0 : 1, count );
1022         
1023         cleanUp.detach();
1024 };
1025
1026 test("remove()", function() {
1027         testRemove("remove");
1028 });
1029
1030 test("detach()", function() {
1031         testRemove("detach");
1032 });
1033
1034 test("empty()", function() {
1035         expect(3);
1036         equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1037         equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1038
1039         // using contents will get comments regular, text, and comment nodes
1040         var j = jQuery("#nonnodes").contents();
1041         j.empty();
1042         equals( j.html(), "", "Check node,textnode,comment empty works" );
1043 });
1044
1045 test("jQuery.cleanData", function() {
1046         expect(14);
1047         
1048         var type, pos, div, child;
1049         
1050         type = "remove";
1051         
1052         // Should trigger 4 remove event
1053         div = getDiv().remove();
1054         
1055         // Should both do nothing
1056         pos = "Outer";
1057         div.trigger("click");
1058         
1059         pos = "Inner";
1060         div.children().trigger("click");
1061         
1062         type = "empty";
1063         div = getDiv();
1064         child = div.children();
1065         
1066         // Should trigger 2 remove event
1067         div.empty();
1068         
1069         // Should trigger 1
1070         pos = "Outer";
1071         div.trigger("click");
1072         
1073         // Should do nothing
1074         pos = "Inner";
1075         child.trigger("click");
1076
1077         // Should trigger 2
1078         div.remove();
1079         
1080         type = "html";
1081         
1082         div = getDiv();
1083         child = div.children();
1084         
1085         // Should trigger 2 remove event
1086         div.html("<div></div>");
1087         
1088         // Should trigger 1
1089         pos = "Outer";
1090         div.trigger("click");
1091         
1092         // Should do nothing
1093         pos = "Inner";
1094         child.trigger("click");
1095
1096         // Should trigger 2
1097         div.remove();
1098         
1099         function getDiv() {
1100                 var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
1101                         ok( true, type + " " + pos + " Click event fired." );
1102                 }).focus(function(){
1103                         ok( true, type + " " + pos + " Focus event fired." );
1104                 }).find("div").click(function(){
1105                         ok( false, type + " " + pos + " Click event fired." );
1106                 }).focus(function(){
1107                         ok( false, type + " " + pos + " Focus event fired." );
1108                 }).end().appendTo("body");
1109                 
1110                 div[0].detachEvent = div[0].removeEventListener = function(t){
1111                         ok( true, type + " Outer " + t + " event unbound" );
1112                 };
1113                 
1114                 div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
1115                         ok( true, type + " Inner " + t + " event unbound" );
1116                 };
1117                 
1118                 return div;
1119         }
1120 });