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
86 j = jQuery("<label/>").wrap(val( "<li/>" ));
87 equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
88 equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
90 // Wrap an element containing a text node
91 j = jQuery("<span/>").wrap("<div>test</div>");
92 equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
93 equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
95 // Try to wrap an element with multiple elements (should fail)
96 j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
97 equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
98 equals( j.length, 1, "There should only be one element (no cloning)." );
99 equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
101 // Wrap an element with a jQuery set
102 j = jQuery("<span/>").wrap(jQuery("<div></div>"));
103 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
105 // Wrap an element with a jQuery set and event
106 result = jQuery("<div></div>").click(function(){
107 ok(true, "Event triggered.");
110 j = jQuery("<span/>").wrap(result);
111 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
113 j.parent().trigger("click");
116 test("wrap(String|Element)", function() {
120 test("wrap(Function)", function() {
121 testWrap(functionReturningObj);
124 var testWrapAll = function(val) {
126 var prev = jQuery("#firstp")[0].previousSibling;
127 var p = jQuery("#firstp,#first")[0].parentNode;
129 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
130 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
131 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
132 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
133 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
134 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
137 var prev = jQuery("#firstp")[0].previousSibling;
138 var p = jQuery("#first")[0].parentNode;
139 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
140 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
141 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
142 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
145 test("wrapAll(String|Element)", function() {
146 testWrapAll(bareObj);
149 var testWrapInner = function(val) {
151 var num = jQuery("#first").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" );
158 var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
159 var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
160 equals( jQuery("#first").children().length, 1, "Only one child" );
161 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
162 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
165 var num = jQuery("#first").children().length;
166 var result = jQuery('#first').wrapInner(val(document.getElementById('empty')));
167 equals( jQuery("#first").children().length, 1, "Only one child" );
168 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
169 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
171 var div = jQuery("<div/>");
172 div.wrapInner(val("<span></span>"));
173 equals(div.children().length, 1, "The contents were wrapped.");
174 equals(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
177 test("wrapInner(String|Element)", function() {
178 testWrapInner(bareObj);
181 test("wrapInner(Function)", function() {
182 testWrapInner(functionReturningObj)
185 test("unwrap()", function() {
188 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>');
190 var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(),
191 abcdef = jQuery('#unwrap span').get();
193 equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
194 same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' );
196 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' );
198 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' );
200 same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' );
202 same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' );
204 same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' );
205 same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' );
207 same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
209 jQuery('body > span.unwrap').remove();
212 var testAppend = function(valueObj) {
214 var defaultText = 'Try them out:'
215 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
216 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
217 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
220 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
221 jQuery('#sap').append(valueObj(document.getElementById('first')));
222 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
225 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
226 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
227 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
230 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
231 jQuery('#sap').append(valueObj(jQuery("#yahoo, #first")));
232 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
235 jQuery("#sap").append(valueObj( 5 ));
236 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
239 jQuery("#sap").append(valueObj( " text with spaces " ));
240 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
243 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
244 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
245 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
248 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />'));
249 jQuery("form input[name=radiotest]").each(function(){
250 ok( jQuery(this).is(':checked'), "Append checked radio");
254 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked = \'checked\' />'));
255 jQuery("form input[name=radiotest]").each(function(){
256 ok( jQuery(this).is(':checked'), "Append alternately formated checked radio");
260 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked />'));
261 jQuery("form input[name=radiotest]").each(function(){
262 ok( jQuery(this).is(':checked'), "Append HTML5-formated checked radio");
266 jQuery("#sap").append(valueObj( document.getElementById('form') ));
267 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
272 var body = jQuery("#iframe")[0].contentWindow.document.body;
275 jQuery( body ).append(valueObj( "<div>test</div>" ));
279 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
282 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
283 t( 'Append legend', '#legend', ['legend'] );
286 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
287 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
289 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
290 ok( jQuery('#table colgroup').length, "Append colgroup" );
292 jQuery('#table colgroup').append(valueObj( '<col/>' ));
293 ok( jQuery('#table colgroup col').length, "Append col" );
296 jQuery('#table').append(valueObj( '<caption></caption>' ));
297 ok( jQuery('#table caption').length, "Append caption" );
301 .append(valueObj( '<select id="appendSelect1"></select>' ))
302 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
304 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
306 equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
308 // using contents will get comments regular, text, and comment nodes
309 var j = jQuery("#nonnodes").contents();
310 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
311 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
312 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
313 d.contents().appendTo("#nonnodes");
315 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
318 test("append(String|Element|Array<Element>|jQuery)", function() {
322 test("append(Function)", function() {
323 testAppend(functionReturningObj);
326 test("append(Function) with incoming value", function() {
329 var defaultText = 'Try them out:', old = jQuery("#first").html();
331 var result = jQuery('#first').append(function(i, val){
332 equals( val, old, "Make sure the incoming value is correct." );
333 return '<b>buga</b>';
335 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
337 var select = jQuery('#select3');
340 equals( select.append(function(i, val){
341 equals( val, old, "Make sure the incoming value is correct." );
342 return '<option value="appendTest">Append Test</option>';
343 }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
346 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
347 old = jQuery("#sap").html();
349 jQuery('#sap').append(function(i, val){
350 equals( val, old, "Make sure the incoming value is correct." );
351 return document.getElementById('first');
353 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
356 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
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'), document.getElementById('yahoo')];
363 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
366 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
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 jQuery("#yahoo, #first");
373 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
376 old = jQuery("#sap").html();
378 jQuery("#sap").append(function(i, val){
379 equals( val, old, "Make sure the incoming value is correct." );
382 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
387 test("append the same fragment with events (Bug #6997, 5566)", function () {
388 expect(4 + (document.fireEvent ? 1 : 0));
393 // This patch modified the way that cloning occurs in IE; we need to make sure that
394 // native event handlers on the original object don't get disturbed when they are
395 // modified on the clone
396 if (!jQuery.support.noCloneEvent && document.fireEvent) {
397 element = jQuery("div:first").click(function () {
398 ok(true, "Event exists on original after being unbound on clone");
399 jQuery(this).unbind('click');
401 element.clone(true).unbind('click')[0].fireEvent('onclick');
402 element[0].fireEvent('onclick');
405 element = jQuery("<a class='test6997'></a>").click(function () {
406 ok(true, "Append second element events work");
409 jQuery("#listWithTabIndex li").append(element)
410 .find('a.test6997').eq(1).click();
412 element = jQuery("<li class='test6997'></li>").click(function () {
413 ok(true, "Before second element events work");
417 jQuery("#listWithTabIndex li").before(element);
418 jQuery("#listWithTabIndex li.test6997").eq(1).click();
420 element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
422 equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
424 element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
426 equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
429 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
432 var defaultText = 'Try them out:'
433 jQuery('<b>buga</b>').appendTo('#first');
434 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
435 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
438 var l = jQuery("#first").children().length + 2;
439 jQuery("<strong>test</strong>");
440 jQuery("<strong>test</strong>");
441 jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ])
443 equals( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
444 equals( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." );
447 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
448 jQuery(document.getElementById('first')).appendTo('#sap');
449 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
452 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
453 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
454 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
457 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
460 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
461 jQuery("#yahoo, #first").appendTo('#sap');
462 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
465 jQuery('#select1').appendTo('#foo');
466 t( 'Append select', '#foo select', ['select1'] );
469 var div = jQuery("<div/>").click(function(){
470 ok(true, "Running a cloned click.");
472 div.appendTo("#main, #moretests");
474 jQuery("#main div:last").click();
475 jQuery("#moretests div:last").click();
478 var div = jQuery("<div/>").appendTo("#main, #moretests");
480 equals( div.length, 2, "appendTo returns the inserted elements" );
482 div.addClass("test");
484 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
485 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
489 div = jQuery("<div/>");
490 jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
492 equals( div.children().length, 1, "Make sure the right number of children were inserted." );
494 div = jQuery("#moretests div");
496 var num = jQuery("#main div").length;
497 div.remove().appendTo("#main");
499 equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." );
504 var testPrepend = function(val) {
506 var defaultText = 'Try them out:'
507 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
508 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
509 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
512 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
513 jQuery('#sap').prepend(val( document.getElementById('first') ));
514 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
517 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
518 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
519 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
522 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
523 jQuery('#sap').prepend(val( jQuery("#yahoo, #first") ));
524 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
527 test("prepend(String|Element|Array<Element>|jQuery)", function() {
528 testPrepend(bareObj);
531 test("prepend(Function)", function() {
532 testPrepend(functionReturningObj);
535 test("prepend(Function) with incoming value", function() {
538 var defaultText = 'Try them out:', old = jQuery('#first').html();
539 var result = jQuery('#first').prepend(function(i, val) {
540 equals( val, old, "Make sure the incoming value is correct." );
541 return '<b>buga</b>';
543 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
545 old = jQuery("#select3").html();
547 equals( jQuery('#select3').prepend(function(i, val) {
548 equals( val, old, "Make sure the incoming value is correct." );
549 return '<option value="prependTest">Prepend Test</option>';
550 }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
553 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
554 old = jQuery('#sap').html();
556 jQuery('#sap').prepend(function(i, val) {
557 equals( val, old, "Make sure the incoming value is correct." );
558 return document.getElementById('first');
561 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
564 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
565 old = jQuery('#sap').html();
567 jQuery('#sap').prepend(function(i, val) {
568 equals( val, old, "Make sure the incoming value is correct." );
569 return [document.getElementById('first'), document.getElementById('yahoo')];
572 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
575 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
576 old = jQuery('#sap').html();
578 jQuery('#sap').prepend(function(i, val) {
579 equals( val, old, "Make sure the incoming value is correct." );
580 return jQuery("#yahoo, #first");
583 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
586 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
588 var defaultText = 'Try them out:'
589 jQuery('<b>buga</b>').prependTo('#first');
590 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
591 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
594 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
595 jQuery(document.getElementById('first')).prependTo('#sap');
596 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
599 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
600 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
601 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
604 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
605 jQuery("#yahoo, #first").prependTo('#sap');
606 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
609 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
610 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
612 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
615 var testBefore = function(val) {
617 var expected = 'This is a normal link: bugaYahoo';
618 jQuery('#yahoo').before(val( '<b>buga</b>' ));
619 equals( jQuery('#en').text(), expected, 'Insert String before' );
622 expected = "This is a normal link: Try them out:Yahoo";
623 jQuery('#yahoo').before(val( document.getElementById('first') ));
624 equals( jQuery('#en').text(), expected, "Insert element before" );
627 expected = "This is a normal link: Try them out:diveintomarkYahoo";
628 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
629 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
632 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
633 jQuery('#yahoo').before(val( jQuery("#mark, #first") ));
634 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
636 var set = jQuery("<div/>").before("<span>test</span>");
637 equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
638 equals( set.length, 2, "Insert the element before the disconnected node." );
641 test("before(String|Element|Array<Element>|jQuery)", function() {
645 test("before(Function)", function() {
646 testBefore(functionReturningObj);
649 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
651 var expected = 'This is a normal link: bugaYahoo';
652 jQuery('<b>buga</b>').insertBefore('#yahoo');
653 equals( jQuery('#en').text(), expected, 'Insert String before' );
656 expected = "This is a normal link: Try them out:Yahoo";
657 jQuery(document.getElementById('first')).insertBefore('#yahoo');
658 equals( jQuery('#en').text(), expected, "Insert element before" );
661 expected = "This is a normal link: Try them out:diveintomarkYahoo";
662 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
663 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
666 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
667 jQuery("#mark, #first").insertBefore('#yahoo');
668 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
671 var testAfter = function(val) {
673 var expected = 'This is a normal link: Yahoobuga';
674 jQuery('#yahoo').after(val( '<b>buga</b>' ));
675 equals( jQuery('#en').text(), expected, 'Insert String after' );
678 expected = "This is a normal link: YahooTry them out:";
679 jQuery('#yahoo').after(val( document.getElementById('first') ));
680 equals( jQuery('#en').text(), expected, "Insert element after" );
683 expected = "This is a normal link: YahooTry them out:diveintomark";
684 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
685 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
688 expected = "This is a normal link: YahoodiveintomarkTry them out:";
689 jQuery('#yahoo').after(val( jQuery("#mark, #first") ));
690 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
692 var set = jQuery("<div/>").after("<span>test</span>");
693 equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
694 equals( set.length, 2, "Insert the element after the disconnected node." );
697 test("after(String|Element|Array<Element>|jQuery)", function() {
701 test("after(Function)", function() {
702 testAfter(functionReturningObj);
705 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
707 var expected = 'This is a normal link: Yahoobuga';
708 jQuery('<b>buga</b>').insertAfter('#yahoo');
709 equals( jQuery('#en').text(), expected, 'Insert String after' );
712 expected = "This is a normal link: YahooTry them out:";
713 jQuery(document.getElementById('first')).insertAfter('#yahoo');
714 equals( jQuery('#en').text(), expected, "Insert element after" );
717 expected = "This is a normal link: YahooTry them out:diveintomark";
718 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
719 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
722 expected = "This is a normal link: YahoodiveintomarkTry them out:";
723 jQuery("#mark, #first").insertAfter('#yahoo');
724 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
727 var testReplaceWith = function(val) {
729 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
730 ok( jQuery("#replace")[0], 'Replace element with string' );
731 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
734 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
735 ok( jQuery("#first")[0], 'Replace element with element' );
736 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
739 jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
740 jQuery('#baz').replaceWith("Baz");
741 equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
742 ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
745 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
746 ok( jQuery("#first")[0], 'Replace element with array of elements' );
747 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
748 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
751 jQuery('#yahoo').replaceWith(val( jQuery("#mark, #first") ));
752 ok( jQuery("#first")[0], 'Replace element with set of elements' );
753 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
754 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
757 var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
758 var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
759 var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
761 y.replaceWith( tmp );
764 y.click(); // Shouldn't be run
765 child.click(); // Shouldn't be run
773 y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
774 var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
776 y.replaceWith( child2 );
785 var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
786 equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
787 equals( set.length, 1, "Replace the disconnected node." );
789 var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
790 // TODO: Work on jQuery(...) inline script execution
791 //$div.replaceWith("<div class='replacewith'></div><script>" +
792 //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
794 equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
795 jQuery('.replacewith').remove();
799 jQuery("#main").append("<div id='replaceWith'></div>");
800 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
802 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
803 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
805 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
806 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
809 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
810 testReplaceWith(bareObj);
813 test("replaceWith(Function)", function() {
814 testReplaceWith(functionReturningObj);
818 var y = jQuery("#yahoo")[0];
820 jQuery(y).replaceWith(function(){
821 equals( this, y, "Make sure the context is coming in correctly." );
827 test("replaceWith(string) for more than one element", function(){
830 equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed');
832 jQuery('#foo p').replaceWith('<span>bar</span>');
833 equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced');
834 equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced');
837 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
839 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
840 ok( jQuery("#replace")[0], 'Replace element with string' );
841 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
844 jQuery(document.getElementById('first')).replaceAll("#yahoo");
845 ok( jQuery("#first")[0], 'Replace element with element' );
846 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
849 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
850 ok( jQuery("#first")[0], 'Replace element with array of elements' );
851 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
852 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
855 jQuery("#mark, #first").replaceAll("#yahoo");
856 ok( jQuery("#first")[0], 'Replace element with set of elements' );
857 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
858 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
861 test("clone()", function() {
863 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
864 var clone = jQuery('#yahoo').clone();
865 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
866 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
869 "<table/>", "<tr/>", "<td/>", "<div/>",
870 "<button/>", "<ul/>", "<ol/>", "<li/>",
871 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
872 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
874 for (var i = 0; i < cloneTags.length; i++) {
875 var j = jQuery(cloneTags[i]);
876 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]);
879 // using contents will get comments regular, text, and comment nodes
880 var cl = jQuery("#nonnodes").contents().clone();
881 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
883 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
884 ok( true, "Bound event still exists." );
887 div = div.clone(true).clone(true);
888 equals( div.length, 1, "One element cloned" );
889 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
890 div.trigger("click");
892 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
893 div.find("table").click(function(){
894 ok( true, "Bound event still exists." );
897 div = div.clone(true);
898 equals( div.length, 1, "One element cloned" );
899 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
900 div.find("table:last").trigger("click");
902 // this is technically an invalid object, but because of the special
903 // classid instantiation it is the only kind that IE has trouble with,
904 // so let's test with it too.
905 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>');
907 clone = div.clone(true);
908 equals( clone.length, 1, "One element cloned" );
909 equals( clone.html(), div.html(), "Element contents cloned" );
910 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
912 // and here's a valid one.
913 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>');
915 clone = div.clone(true);
916 equals( clone.length, 1, "One element cloned" );
917 equals( clone.html(), div.html(), "Element contents cloned" );
918 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
920 div = jQuery("<div/>").data({ a: true, b: true });
921 div = div.clone(true);
922 equals( div.data("a"), true, "Data cloned." );
923 equals( div.data("b"), true, "Data cloned." );
925 var form = document.createElement("form");
926 form.action = "/test/";
927 var div = document.createElement("div");
928 div.appendChild( document.createTextNode("test") );
929 form.appendChild( div );
931 equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
933 equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
937 test("clone() on XML nodes", function() {
940 jQuery.get("data/dashboard.xml", function (xml) {
941 var root = jQuery(xml.documentElement).clone();
942 var origTab = jQuery("tab", xml).eq(0);
943 var cloneTab = jQuery("tab", root).eq(0);
944 origTab.text("origval");
945 cloneTab.text("cloneval");
946 equals(origTab.text(), "origval", "Check original XML node was correctly set");
947 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
953 var testHtml = function(valueObj) {
956 jQuery.scriptorder = 0;
958 var div = jQuery("#main > div");
959 div.html(valueObj("<b>test</b>"));
961 for ( var i = 0; i < div.size(); i++ ) {
962 if ( div.get(i).childNodes.length != 1 ) pass = false;
964 ok( pass, "Set HTML" );
966 div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
968 equals( div.children().length, 2, "Make sure two child nodes exist." );
969 equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
971 var space = jQuery("<div/>").html(valueObj(" "))[0].innerHTML;
972 ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." );
973 equals( jQuery("<div/>").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." );
975 jQuery("#main").html(valueObj("<style>.foobar{color:green;}</style>"));
977 equals( jQuery("#main").children().length, 1, "Make sure there is a child element." );
978 equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
981 // using contents will get comments regular, text, and comment nodes
982 var j = jQuery("#nonnodes").contents();
983 j.html(valueObj("<b>bold</b>"));
985 // this is needed, or the expando added by jQuery unique will yield a different html
986 j.find('b').removeData();
987 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
989 jQuery("#main").html(valueObj("<select/>"));
990 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
991 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
993 var $div = jQuery('<div />');
994 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
995 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
997 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
998 equals( $div2.html(insert).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
999 equals( $div2.html("x" + insert).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1000 equals( $div2.html(" " + insert).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1002 var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
1004 equals( map[0].childNodes.length, 1, "The area was inserted." );
1005 equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
1009 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>'));
1011 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1012 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1013 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1015 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
1017 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>'));
1019 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>"));
1022 test("html(String)", function() {
1026 test("html(Function)", function() {
1027 testHtml(functionReturningObj);
1033 jQuery("#main").html(function(){
1034 return jQuery(this).text();
1037 ok( !/</.test( jQuery("#main").html() ), "Replace html with text." );
1038 ok( jQuery("#main").html().length > 0, "Make sure text exists." );
1041 test("html(Function) with incoming value", function() {
1044 var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
1046 div.html(function(i, val) {
1047 equals( val, old[i], "Make sure the incoming value is correct." );
1048 return "<b>test</b>";
1052 div.each(function(){
1053 if ( this.childNodes.length !== 1 ) {
1057 ok( pass, "Set HTML" );
1060 // using contents will get comments regular, text, and comment nodes
1061 var j = jQuery("#nonnodes").contents();
1062 old = j.map(function(){ return jQuery(this).html(); });
1064 j.html(function(i, val) {
1065 equals( val, old[i], "Make sure the incoming value is correct." );
1066 return "<b>bold</b>";
1069 // Handle the case where no comment is in the document
1070 if ( j.length === 2 ) {
1071 equals( null, null, "Make sure the incoming value is correct." );
1074 j.find('b').removeData();
1075 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1077 var $div = jQuery('<div />');
1079 equals( $div.html(function(i, val) {
1080 equals( val, "", "Make sure the incoming value is correct." );
1082 }).html(), '5', 'Setting a number as html' );
1084 equals( $div.html(function(i, val) {
1085 equals( val, "5", "Make sure the incoming value is correct." );
1087 }).html(), '0', 'Setting a zero as html' );
1089 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1090 equals( $div2.html(function(i, val) {
1091 equals( val, "", "Make sure the incoming value is correct." );
1093 }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1095 equals( $div2.html(function(i, val) {
1096 equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
1097 return "x" + insert;
1098 }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1100 equals( $div2.html(function(i, val) {
1101 equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
1102 return " " + insert;
1103 }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1106 var testRemove = function(method) {
1109 var first = jQuery("#ap").children(":first");
1110 first.data("foo", "bar");
1112 jQuery("#ap").children()[method]();
1113 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1114 equals( jQuery("#ap").children().length, 0, "Check remove" );
1116 equals( first.data("foo"), method == "remove" ? null : "bar" );
1119 jQuery("#ap").children()[method]("a");
1120 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1121 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1123 jQuery("#ap").children()[method]("a, code");
1124 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
1126 // using contents will get comments regular, text, and comment nodes
1127 // Handle the case where no comment is in the document
1128 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
1129 jQuery("#nonnodes").contents()[method]();
1130 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1135 var first = jQuery("#ap").children(":first");
1136 var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
1138 equals( method == "remove" ? 0 : 1, count );
1143 test("remove()", function() {
1144 testRemove("remove");
1147 test("detach()", function() {
1148 testRemove("detach");
1151 test("empty()", function() {
1153 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1154 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1156 // using contents will get comments regular, text, and comment nodes
1157 var j = jQuery("#nonnodes").contents();
1159 equals( j.html(), "", "Check node,textnode,comment empty works" );
1162 test("jQuery.cleanData", function() {
1165 var type, pos, div, child;
1169 // Should trigger 4 remove event
1170 div = getDiv().remove();
1172 // Should both do nothing
1174 div.trigger("click");
1177 div.children().trigger("click");
1181 child = div.children();
1183 // Should trigger 2 remove event
1188 div.trigger("click");
1190 // Should do nothing
1192 child.trigger("click");
1200 child = div.children();
1202 // Should trigger 2 remove event
1203 div.html("<div></div>");
1207 div.trigger("click");
1209 // Should do nothing
1211 child.trigger("click");
1217 var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
1218 ok( true, type + " " + pos + " Click event fired." );
1219 }).focus(function(){
1220 ok( true, type + " " + pos + " Focus event fired." );
1221 }).find("div").click(function(){
1222 ok( false, type + " " + pos + " Click event fired." );
1223 }).focus(function(){
1224 ok( false, type + " " + pos + " Focus event fired." );
1225 }).end().appendTo("body");
1227 div[0].detachEvent = div[0].removeEventListener = function(t){
1228 ok( true, type + " Outer " + t + " event unbound" );
1231 div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
1232 ok( true, type + " Inner " + t + " event unbound" );