1 module("manipulation");
3 var bareObj = function(value) { return value; };
4 var functionReturningObj = function(value) { return (function() { return value; }); };
6 test("text()", function() {
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.' );
11 // Check serialization of text values
12 equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
15 var testText = function(valueObj) {
17 var val = valueObj("<div><b>Hello</b> cruel world!</div>");
18 equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
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()" );
26 // Blackberry 4.6 doesn't maintain comments in the DOM
27 equals( jQuery("#nonnodes")[0].childNodes.length < 3 ? 8 : j[2].nodeType, 8, "Check node,textnode,comment with text()" );
30 test("text(String)", function() {
34 test("text(Function)", function() {
35 testText(functionReturningObj);
38 test("text(Function) with incoming value", function() {
41 var old = "This link has class=\"blog\": Simon Willison's Weblog";
43 jQuery('#sap').text(function(i, val) {
44 equals( val, old, "Make sure the incoming value is correct." );
48 equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
53 var testWrap = function(val) {
55 var defaultText = 'Try them out:'
56 var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text();
57 equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
58 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
61 var defaultText = 'Try them out:'
62 var result = jQuery('#first').wrap(val( document.getElementById('empty') )).parent();
63 ok( result.is('ol'), 'Check for element wrapping' );
64 equals( result.text(), defaultText, 'Check for element wrapping' );
67 jQuery('#check1').click(function() {
69 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
70 jQuery(checkbox).wrap(val( '<div id="c1" style="display:none;"></div>' ));
71 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
74 // using contents will get comments regular, text, and comment nodes
75 var j = jQuery("#nonnodes").contents();
76 j.wrap(val( "<i></i>" ));
78 // Blackberry 4.6 doesn't maintain comments in the DOM
79 equals( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[0].childNodes.length, "Check node,textnode,comment wraps ok" );
80 equals( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
82 // Try wrapping a disconnected node
84 for (var i in jQuery.cache) {
88 j = jQuery("<label/>").wrap(val( "<li/>" ));
89 equals( j[0].nodeName.toUpperCase(), "LABEL", "Element is a label" );
90 equals( j[0].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
92 for (i in jQuery.cache) {
95 equals(cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)");
97 // Wrap an element containing a text node
98 j = jQuery("<span/>").wrap("<div>test</div>");
99 equals( j[0].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
100 equals( j[0].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
102 // Try to wrap an element with multiple elements (should fail)
103 j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
104 equals( j[0].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
105 equals( j.length, 1, "There should only be one element (no cloning)." );
106 equals( j[0].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
108 // Wrap an element with a jQuery set
109 j = jQuery("<span/>").wrap(jQuery("<div></div>"));
110 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
112 // Wrap an element with a jQuery set and event
113 result = jQuery("<div></div>").click(function(){
114 ok(true, "Event triggered.");
117 j = jQuery("<span/>").wrap(result);
118 equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
120 j.parent().trigger("click");
123 test("wrap(String|Element)", function() {
127 test("wrap(Function)", function() {
128 testWrap(functionReturningObj);
131 var testWrapAll = function(val) {
133 var prev = jQuery("#firstp")[0].previousSibling;
134 var p = jQuery("#firstp,#first")[0].parentNode;
136 var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' ));
137 equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
138 ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
139 ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
140 equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
141 equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
144 var prev = jQuery("#firstp")[0].previousSibling;
145 var p = jQuery("#first")[0].parentNode;
146 var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') ));
147 equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
148 equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
149 equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
152 test("wrapAll(String|Element)", function() {
153 testWrapAll(bareObj);
156 var testWrapInner = function(val) {
158 var num = jQuery("#first").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").html("foo<div>test</div><div>test2</div>").children().length;
166 var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>'));
167 equals( jQuery("#first").children().length, 1, "Only one child" );
168 ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
169 equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
172 var num = jQuery("#first").children().length;
173 var result = jQuery('#first').wrapInner(val(document.getElementById('empty')));
174 equals( jQuery("#first").children().length, 1, "Only one child" );
175 ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
176 equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
178 var div = jQuery("<div/>");
179 div.wrapInner(val("<span></span>"));
180 equals(div.children().length, 1, "The contents were wrapped.");
181 equals(div.children()[0].nodeName.toLowerCase(), "span", "A span was inserted.");
184 test("wrapInner(String|Element)", function() {
185 testWrapInner(bareObj);
188 test("wrapInner(Function)", function() {
189 testWrapInner(functionReturningObj)
192 test("unwrap()", function() {
195 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>');
197 var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(),
198 abcdef = jQuery('#unwrap span').get();
200 equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' );
201 same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' );
203 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' );
205 same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' );
207 same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' );
209 same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' );
211 same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' );
212 same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' );
214 same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
216 jQuery('body > span.unwrap').remove();
219 var testAppend = function(valueObj) {
221 var defaultText = 'Try them out:'
222 var result = jQuery('#first').append(valueObj('<b>buga</b>'));
223 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
224 equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
227 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
228 jQuery('#sap').append(valueObj(document.getElementById('first')));
229 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
232 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
233 jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')]));
234 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
237 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
238 jQuery('#sap').append(valueObj(jQuery("#yahoo, #first")));
239 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
242 jQuery("#sap").append(valueObj( 5 ));
243 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
246 jQuery("#sap").append(valueObj( " text with spaces " ));
247 ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
250 ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
251 ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
252 ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
255 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />'));
256 jQuery("form input[name=radiotest]").each(function(){
257 ok( jQuery(this).is(':checked'), "Append checked radio");
261 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked = \'checked\' />'));
262 jQuery("form input[name=radiotest]").each(function(){
263 ok( jQuery(this).is(':checked'), "Append alternately formated checked radio");
267 jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked />'));
268 jQuery("form input[name=radiotest]").each(function(){
269 ok( jQuery(this).is(':checked'), "Append HTML5-formated checked radio");
273 jQuery("#sap").append(valueObj( document.getElementById('form') ));
274 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
279 var body = jQuery("#iframe")[0].contentWindow.document.body;
282 jQuery( body ).append(valueObj( "<div>test</div>" ));
286 ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
289 jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' ));
290 t( 'Append legend', '#legend', ['legend'] );
293 jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' ));
294 equals( jQuery('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" );
296 jQuery('#table').append(valueObj( '<colgroup></colgroup>' ));
297 ok( jQuery('#table colgroup').length, "Append colgroup" );
299 jQuery('#table colgroup').append(valueObj( '<col/>' ));
300 ok( jQuery('#table colgroup col').length, "Append col" );
303 jQuery('#table').append(valueObj( '<caption></caption>' ));
304 ok( jQuery('#table caption').length, "Append caption" );
308 .append(valueObj( '<select id="appendSelect1"></select>' ))
309 .append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' ));
311 t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
313 equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
315 // using contents will get comments regular, text, and comment nodes
316 var j = jQuery("#nonnodes").contents();
317 var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
318 equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
319 ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
320 d.contents().appendTo("#nonnodes");
322 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
325 test("append(String|Element|Array<Element>|jQuery)", function() {
329 test("append(Function)", function() {
330 testAppend(functionReturningObj);
333 test("append(Function) with incoming value", function() {
336 var defaultText = 'Try them out:', old = jQuery("#first").html();
338 var result = jQuery('#first').append(function(i, val){
339 equals( val, old, "Make sure the incoming value is correct." );
340 return '<b>buga</b>';
342 equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
344 var select = jQuery('#select3');
347 equals( select.append(function(i, val){
348 equals( val, old, "Make sure the incoming value is correct." );
349 return '<option value="appendTest">Append Test</option>';
350 }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
353 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
354 old = jQuery("#sap").html();
356 jQuery('#sap').append(function(i, val){
357 equals( val, old, "Make sure the incoming value is correct." );
358 return document.getElementById('first');
360 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
363 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
364 old = jQuery("#sap").html();
366 jQuery('#sap').append(function(i, val){
367 equals( val, old, "Make sure the incoming value is correct." );
368 return [document.getElementById('first'), document.getElementById('yahoo')];
370 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
373 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
374 old = jQuery("#sap").html();
376 jQuery('#sap').append(function(i, val){
377 equals( val, old, "Make sure the incoming value is correct." );
378 return jQuery("#yahoo, #first");
380 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
383 old = jQuery("#sap").html();
385 jQuery("#sap").append(function(i, val){
386 equals( val, old, "Make sure the incoming value is correct." );
389 ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
394 test("append the same fragment with events (Bug #6997, 5566)", function () {
395 expect(4 + (document.fireEvent ? 1 : 0));
400 // This patch modified the way that cloning occurs in IE; we need to make sure that
401 // native event handlers on the original object don't get disturbed when they are
402 // modified on the clone
403 if (!jQuery.support.noCloneEvent && document.fireEvent) {
404 element = jQuery("div:first").click(function () {
405 ok(true, "Event exists on original after being unbound on clone");
406 jQuery(this).unbind('click');
408 element.clone(true).unbind('click')[0].fireEvent('onclick');
409 element[0].fireEvent('onclick');
412 element = jQuery("<a class='test6997'></a>").click(function () {
413 ok(true, "Append second element events work");
416 jQuery("#listWithTabIndex li").append(element)
417 .find('a.test6997').eq(1).click();
419 element = jQuery("<li class='test6997'></li>").click(function () {
420 ok(true, "Before second element events work");
424 jQuery("#listWithTabIndex li").before(element);
425 jQuery("#listWithTabIndex li.test6997").eq(1).click();
427 element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
429 equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
431 element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
433 equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
436 test("appendTo(String|Element|Array<Element>|jQuery)", function() {
439 var defaultText = 'Try them out:'
440 jQuery('<b>buga</b>').appendTo('#first');
441 equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
442 equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
445 var l = jQuery("#first").children().length + 2;
446 jQuery("<strong>test</strong>");
447 jQuery("<strong>test</strong>");
448 jQuery([ jQuery("<strong>test</strong>")[0], jQuery("<strong>test</strong>")[0] ])
450 equals( jQuery("#first").children().length, l, "Make sure the elements were inserted." );
451 equals( jQuery("#first").children().last()[0].nodeName.toLowerCase(), "strong", "Verify the last element." );
454 var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
455 jQuery(document.getElementById('first')).appendTo('#sap');
456 equals( jQuery('#sap').text(), expected, "Check for appending of element" );
459 expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
460 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
461 equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" );
464 ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
467 expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
468 jQuery("#yahoo, #first").appendTo('#sap');
469 equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" );
472 jQuery('#select1').appendTo('#foo');
473 t( 'Append select', '#foo select', ['select1'] );
476 var div = jQuery("<div/>").click(function(){
477 ok(true, "Running a cloned click.");
479 div.appendTo("#main, #moretests");
481 jQuery("#main div:last").click();
482 jQuery("#moretests div:last").click();
485 var div = jQuery("<div/>").appendTo("#main, #moretests");
487 equals( div.length, 2, "appendTo returns the inserted elements" );
489 div.addClass("test");
491 ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" );
492 ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" );
496 div = jQuery("<div/>");
497 jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div );
499 equals( div.children().length, 1, "Make sure the right number of children were inserted." );
501 div = jQuery("#moretests div");
503 var num = jQuery("#main div").length;
504 div.remove().appendTo("#main");
506 equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." );
511 var testPrepend = function(val) {
513 var defaultText = 'Try them out:'
514 var result = jQuery('#first').prepend(val( '<b>buga</b>' ));
515 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
516 equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
519 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
520 jQuery('#sap').prepend(val( document.getElementById('first') ));
521 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
524 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
525 jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] ));
526 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
529 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
530 jQuery('#sap').prepend(val( jQuery("#yahoo, #first") ));
531 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
534 test("prepend(String|Element|Array<Element>|jQuery)", function() {
535 testPrepend(bareObj);
538 test("prepend(Function)", function() {
539 testPrepend(functionReturningObj);
542 test("prepend(Function) with incoming value", function() {
545 var defaultText = 'Try them out:', old = jQuery('#first').html();
546 var result = jQuery('#first').prepend(function(i, val) {
547 equals( val, old, "Make sure the incoming value is correct." );
548 return '<b>buga</b>';
550 equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
552 old = jQuery("#select3").html();
554 equals( jQuery('#select3').prepend(function(i, val) {
555 equals( val, old, "Make sure the incoming value is correct." );
556 return '<option value="prependTest">Prepend Test</option>';
557 }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
560 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
561 old = jQuery('#sap').html();
563 jQuery('#sap').prepend(function(i, val) {
564 equals( val, old, "Make sure the incoming value is correct." );
565 return document.getElementById('first');
568 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
571 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
572 old = jQuery('#sap').html();
574 jQuery('#sap').prepend(function(i, val) {
575 equals( val, old, "Make sure the incoming value is correct." );
576 return [document.getElementById('first'), document.getElementById('yahoo')];
579 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
582 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
583 old = jQuery('#sap').html();
585 jQuery('#sap').prepend(function(i, val) {
586 equals( val, old, "Make sure the incoming value is correct." );
587 return jQuery("#yahoo, #first");
590 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
593 test("prependTo(String|Element|Array<Element>|jQuery)", function() {
595 var defaultText = 'Try them out:'
596 jQuery('<b>buga</b>').prependTo('#first');
597 equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
598 equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
601 var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
602 jQuery(document.getElementById('first')).prependTo('#sap');
603 equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
606 expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
607 jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap');
608 equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
611 expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
612 jQuery("#yahoo, #first").prependTo('#sap');
613 equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
616 jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
617 jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
619 t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
622 var testBefore = function(val) {
624 var expected = 'This is a normal link: bugaYahoo';
625 jQuery('#yahoo').before(val( '<b>buga</b>' ));
626 equals( jQuery('#en').text(), expected, 'Insert String before' );
629 expected = "This is a normal link: Try them out:Yahoo";
630 jQuery('#yahoo').before(val( document.getElementById('first') ));
631 equals( jQuery('#en').text(), expected, "Insert element before" );
634 expected = "This is a normal link: Try them out:diveintomarkYahoo";
635 jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] ));
636 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
639 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
640 jQuery('#yahoo').before(val( jQuery("#mark, #first") ));
641 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
643 var set = jQuery("<div/>").before("<span>test</span>");
644 equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
645 equals( set.length, 2, "Insert the element before the disconnected node." );
648 test("before(String|Element|Array<Element>|jQuery)", function() {
652 test("before(Function)", function() {
653 testBefore(functionReturningObj);
656 test("insertBefore(String|Element|Array<Element>|jQuery)", function() {
658 var expected = 'This is a normal link: bugaYahoo';
659 jQuery('<b>buga</b>').insertBefore('#yahoo');
660 equals( jQuery('#en').text(), expected, 'Insert String before' );
663 expected = "This is a normal link: Try them out:Yahoo";
664 jQuery(document.getElementById('first')).insertBefore('#yahoo');
665 equals( jQuery('#en').text(), expected, "Insert element before" );
668 expected = "This is a normal link: Try them out:diveintomarkYahoo";
669 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
670 equals( jQuery('#en').text(), expected, "Insert array of elements before" );
673 expected = "This is a normal link: diveintomarkTry them out:Yahoo";
674 jQuery("#mark, #first").insertBefore('#yahoo');
675 equals( jQuery('#en').text(), expected, "Insert jQuery before" );
678 var testAfter = function(val) {
680 var expected = 'This is a normal link: Yahoobuga';
681 jQuery('#yahoo').after(val( '<b>buga</b>' ));
682 equals( jQuery('#en').text(), expected, 'Insert String after' );
685 expected = "This is a normal link: YahooTry them out:";
686 jQuery('#yahoo').after(val( document.getElementById('first') ));
687 equals( jQuery('#en').text(), expected, "Insert element after" );
690 expected = "This is a normal link: YahooTry them out:diveintomark";
691 jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] ));
692 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
695 expected = "This is a normal link: YahoodiveintomarkTry them out:";
696 jQuery('#yahoo').after(val( jQuery("#mark, #first") ));
697 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
699 var set = jQuery("<div/>").after("<span>test</span>");
700 equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
701 equals( set.length, 2, "Insert the element after the disconnected node." );
704 test("after(String|Element|Array<Element>|jQuery)", function() {
708 test("after(Function)", function() {
709 testAfter(functionReturningObj);
712 test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
714 var expected = 'This is a normal link: Yahoobuga';
715 jQuery('<b>buga</b>').insertAfter('#yahoo');
716 equals( jQuery('#en').text(), expected, 'Insert String after' );
719 expected = "This is a normal link: YahooTry them out:";
720 jQuery(document.getElementById('first')).insertAfter('#yahoo');
721 equals( jQuery('#en').text(), expected, "Insert element after" );
724 expected = "This is a normal link: YahooTry them out:diveintomark";
725 jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo');
726 equals( jQuery('#en').text(), expected, "Insert array of elements after" );
729 expected = "This is a normal link: YahoodiveintomarkTry them out:";
730 jQuery("#mark, #first").insertAfter('#yahoo');
731 equals( jQuery('#en').text(), expected, "Insert jQuery after" );
734 var testReplaceWith = function(val) {
736 jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
737 ok( jQuery("#replace")[0], 'Replace element with string' );
738 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
741 jQuery('#yahoo').replaceWith(val( document.getElementById('first') ));
742 ok( jQuery("#first")[0], 'Replace element with element' );
743 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
746 jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>');
747 jQuery('#baz').replaceWith("Baz");
748 equals( jQuery("#bar").text(),"Baz", 'Replace element with text' );
749 ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' );
752 jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] ));
753 ok( jQuery("#first")[0], 'Replace element with array of elements' );
754 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
755 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
758 jQuery('#yahoo').replaceWith(val( jQuery("#mark, #first") ));
759 ok( jQuery("#first")[0], 'Replace element with set of elements' );
760 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
761 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
764 var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
765 var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
766 var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
768 y.replaceWith( tmp );
771 y.click(); // Shouldn't be run
772 child.click(); // Shouldn't be run
780 y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
781 var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
783 y.replaceWith( child2 );
792 var set = jQuery("<div/>").replaceWith(val("<span>test</span>"));
793 equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
794 equals( set.length, 1, "Replace the disconnected node." );
796 var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
797 // TODO: Work on jQuery(...) inline script execution
798 //$div.replaceWith("<div class='replacewith'></div><script>" +
799 //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
801 equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
802 jQuery('.replacewith').remove();
806 jQuery("#main").append("<div id='replaceWith'></div>");
807 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
809 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
810 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
812 jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
813 equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
816 test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
817 testReplaceWith(bareObj);
820 test("replaceWith(Function)", function() {
821 testReplaceWith(functionReturningObj);
825 var y = jQuery("#yahoo")[0];
827 jQuery(y).replaceWith(function(){
828 equals( this, y, "Make sure the context is coming in correctly." );
834 test("replaceWith(string) for more than one element", function(){
837 equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed');
839 jQuery('#foo p').replaceWith('<span>bar</span>');
840 equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced');
841 equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced');
844 test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
846 jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
847 ok( jQuery("#replace")[0], 'Replace element with string' );
848 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
851 jQuery(document.getElementById('first')).replaceAll("#yahoo");
852 ok( jQuery("#first")[0], 'Replace element with element' );
853 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
856 jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
857 ok( jQuery("#first")[0], 'Replace element with array of elements' );
858 ok( jQuery("#mark")[0], 'Replace element with array of elements' );
859 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
862 jQuery("#mark, #first").replaceAll("#yahoo");
863 ok( jQuery("#first")[0], 'Replace element with set of elements' );
864 ok( jQuery("#mark")[0], 'Replace element with set of elements' );
865 ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
868 test("clone()", function() {
870 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
871 var clone = jQuery('#yahoo').clone();
872 equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
873 equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
876 "<table/>", "<tr/>", "<td/>", "<div/>",
877 "<button/>", "<ul/>", "<ol/>", "<li/>",
878 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
879 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
881 for (var i = 0; i < cloneTags.length; i++) {
882 var j = jQuery(cloneTags[i]);
883 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]);
886 // using contents will get comments regular, text, and comment nodes
887 var cl = jQuery("#nonnodes").contents().clone();
888 ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
890 var div = jQuery("<div><ul><li>test</li></ul></div>").click(function(){
891 ok( true, "Bound event still exists." );
894 div = div.clone(true).clone(true);
895 equals( div.length, 1, "One element cloned" );
896 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
897 div.trigger("click");
899 div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]);
900 div.find("table").click(function(){
901 ok( true, "Bound event still exists." );
904 div = div.clone(true);
905 equals( div.length, 1, "One element cloned" );
906 equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
907 div.find("table:last").trigger("click");
909 // this is technically an invalid object, but because of the special
910 // classid instantiation it is the only kind that IE has trouble with,
911 // so let's test with it too.
912 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>');
914 clone = div.clone(true);
915 equals( clone.length, 1, "One element cloned" );
916 equals( clone.html(), div.html(), "Element contents cloned" );
917 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
919 // and here's a valid one.
920 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>');
922 clone = div.clone(true);
923 equals( clone.length, 1, "One element cloned" );
924 equals( clone.html(), div.html(), "Element contents cloned" );
925 equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
927 div = jQuery("<div/>").data({
929 c: { nesty: ["Block", "Head"] }
931 var div2 = div.clone(true);
932 equals( div2.data("a"), true, "Data cloned." );
933 equals( div2.data("b"), true, "Data cloned." );
934 var c = div2.data("c");
936 equals( div.data("c").nesty[0], "Block", "Ensure cloned element data is deep copied (Bug #7717)" );
938 var form = document.createElement("form");
939 form.action = "/test/";
940 var div = document.createElement("div");
941 div.appendChild( document.createTextNode("test") );
942 form.appendChild( div );
944 equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
946 equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
950 test("clone() on XML nodes", function() {
953 jQuery.get("data/dashboard.xml", function (xml) {
954 var root = jQuery(xml.documentElement).clone();
955 var origTab = jQuery("tab", xml).eq(0);
956 var cloneTab = jQuery("tab", root).eq(0);
957 origTab.text("origval");
958 cloneTab.text("cloneval");
959 equals(origTab.text(), "origval", "Check original XML node was correctly set");
960 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
966 var testHtml = function(valueObj) {
969 jQuery.scriptorder = 0;
971 var div = jQuery("#main > div");
972 div.html(valueObj("<b>test</b>"));
974 for ( var i = 0; i < div.size(); i++ ) {
975 if ( div.get(i).childNodes.length != 1 ) pass = false;
977 ok( pass, "Set HTML" );
979 div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') );
981 equals( div.children().length, 2, "Make sure two child nodes exist." );
982 equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
984 var space = jQuery("<div/>").html(valueObj(" "))[0].innerHTML;
985 ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." );
986 equals( jQuery("<div/>").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." );
988 jQuery("#main").html(valueObj("<style>.foobar{color:green;}</style>"));
990 equals( jQuery("#main").children().length, 1, "Make sure there is a child element." );
991 equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." );
994 // using contents will get comments regular, text, and comment nodes
995 var j = jQuery("#nonnodes").contents();
996 j.html(valueObj("<b>bold</b>"));
998 // this is needed, or the expando added by jQuery unique will yield a different html
999 j.find('b').removeData();
1000 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1002 jQuery("#main").html(valueObj("<select/>"));
1003 jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
1004 equals( jQuery("#main select").val(), "O2", "Selected option correct" );
1006 var $div = jQuery('<div />');
1007 equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' );
1008 equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' );
1010 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1011 equals( $div2.html(insert).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1012 equals( $div2.html("x" + insert).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1013 equals( $div2.html(" " + insert).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1015 var map = jQuery("<map/>").html(valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"));
1017 equals( map[0].childNodes.length, 1, "The area was inserted." );
1018 equals( map[0].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
1022 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>'));
1024 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1025 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1026 jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
1028 jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>'));
1030 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>'));
1032 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>"));
1035 test("html(String)", function() {
1039 test("html(Function)", function() {
1040 testHtml(functionReturningObj);
1046 jQuery("#main").html(function(){
1047 return jQuery(this).text();
1050 ok( !/</.test( jQuery("#main").html() ), "Replace html with text." );
1051 ok( jQuery("#main").html().length > 0, "Make sure text exists." );
1054 test("html(Function) with incoming value", function() {
1057 var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
1059 div.html(function(i, val) {
1060 equals( val, old[i], "Make sure the incoming value is correct." );
1061 return "<b>test</b>";
1065 div.each(function(){
1066 if ( this.childNodes.length !== 1 ) {
1070 ok( pass, "Set HTML" );
1073 // using contents will get comments regular, text, and comment nodes
1074 var j = jQuery("#nonnodes").contents();
1075 old = j.map(function(){ return jQuery(this).html(); });
1077 j.html(function(i, val) {
1078 equals( val, old[i], "Make sure the incoming value is correct." );
1079 return "<b>bold</b>";
1082 // Handle the case where no comment is in the document
1083 if ( j.length === 2 ) {
1084 equals( null, null, "Make sure the incoming value is correct." );
1087 j.find('b').removeData();
1088 equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1090 var $div = jQuery('<div />');
1092 equals( $div.html(function(i, val) {
1093 equals( val, "", "Make sure the incoming value is correct." );
1095 }).html(), '5', 'Setting a number as html' );
1097 equals( $div.html(function(i, val) {
1098 equals( val, "5", "Make sure the incoming value is correct." );
1100 }).html(), '0', 'Setting a zero as html' );
1102 var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
1103 equals( $div2.html(function(i, val) {
1104 equals( val, "", "Make sure the incoming value is correct." );
1106 }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
1108 equals( $div2.html(function(i, val) {
1109 equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
1110 return "x" + insert;
1111 }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
1113 equals( $div2.html(function(i, val) {
1114 equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
1115 return " " + insert;
1116 }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
1119 var testRemove = function(method) {
1122 var first = jQuery("#ap").children(":first");
1123 first.data("foo", "bar");
1125 jQuery("#ap").children()[method]();
1126 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1127 equals( jQuery("#ap").children().length, 0, "Check remove" );
1129 equals( first.data("foo"), method == "remove" ? null : "bar" );
1132 jQuery("#ap").children()[method]("a");
1133 ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1134 equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1136 jQuery("#ap").children()[method]("a, code");
1137 equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
1139 // using contents will get comments regular, text, and comment nodes
1140 // Handle the case where no comment is in the document
1141 ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" );
1142 jQuery("#nonnodes").contents()[method]();
1143 equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1148 var first = jQuery("#ap").children(":first");
1149 var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
1151 equals( method == "remove" ? 0 : 1, count );
1156 test("remove()", function() {
1157 testRemove("remove");
1160 test("detach()", function() {
1161 testRemove("detach");
1164 test("empty()", function() {
1166 equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1167 equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1169 // using contents will get comments regular, text, and comment nodes
1170 var j = jQuery("#nonnodes").contents();
1172 equals( j.html(), "", "Check node,textnode,comment empty works" );
1175 test("jQuery.cleanData", function() {
1178 var type, pos, div, child;
1182 // Should trigger 4 remove event
1183 div = getDiv().remove();
1185 // Should both do nothing
1187 div.trigger("click");
1190 div.children().trigger("click");
1194 child = div.children();
1196 // Should trigger 2 remove event
1201 div.trigger("click");
1203 // Should do nothing
1205 child.trigger("click");
1213 child = div.children();
1215 // Should trigger 2 remove event
1216 div.html("<div></div>");
1220 div.trigger("click");
1222 // Should do nothing
1224 child.trigger("click");
1230 var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
1231 ok( true, type + " " + pos + " Click event fired." );
1232 }).focus(function(){
1233 ok( true, type + " " + pos + " Focus event fired." );
1234 }).find("div").click(function(){
1235 ok( false, type + " " + pos + " Click event fired." );
1236 }).focus(function(){
1237 ok( false, type + " " + pos + " Focus event fired." );
1238 }).end().appendTo("body");
1240 div[0].detachEvent = div[0].removeEventListener = function(t){
1241 ok( true, type + " Outer " + t + " event unbound" );
1244 div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
1245 ok( true, type + " Inner " + t + " event unbound" );