},
clean: function( elems, context, fragment, scripts ) {
- var j, safe, elem, tag, wrap, depth, div, hasBody, tbody, len, handleScript, jsTags,
- i = 0,
+ var i, j, elem, tag, wrap, depth, div, hasBody, tbody, len, handleScript, jsTags,
+ safe = context === document && safeFragment,
ret = [];
// Ensure that context is a document
}
// Use the already-created safe fragment if context permits
- for ( safe = context === document && safeFragment; (elem = elems[i]) != null; i++ ) {
+ for ( i = 0; (elem = elems[i]) != null; i++ ) {
if ( typeof elem === "number" ) {
elem += "";
}
} else {
// Ensure a safe container in which to render the html
safe = safe || createSafeFragment( context );
- div = div || safe.appendChild( context.createElement("div") );
+ div = context.createElement("div");
+ safe.appendChild( div );
// Fix "XHTML"-style tags in all browsers
elem = elem.replace(rxhtmlTag, "<$1></$2>");
elem = div.childNodes;
- // Remember the top-level container for proper cleanup
- div = safe.lastChild;
+ // Take out of fragment container (we need a fresh div each time)
+ div.parentNode.removeChild( div );
}
}
if ( elem.nodeType ) {
ret.push( elem );
} else {
- ret = jQuery.merge( ret, elem );
+ jQuery.merge( ret, elem );
}
}
// Fix #11356: Clear elements from safeFragment
if ( div ) {
- safe.removeChild( div );
elem = div = safe = null;
}
equal( jQuery(elem).clone().attr("id","clone")[0].checked, true, "Checked true state correctly cloned" );
});
+test("manipulate mixed jQuery and text (#12384, #12346)", function() {
+ expect(2);
+
+ var div = jQuery("<div>a</div>").append( " ", jQuery("<span>b</span>"), " ", jQuery("<span>c</span>") ),
+ nbsp = String.fromCharCode(160);
+ equal( div.text(), "a" + nbsp + "b" + nbsp+ "c", "Appending mixed jQuery with text nodes" );
+
+ div = jQuery("<div><div></div></div>")
+ .find("div")
+ .after("<p>a</p>", "<p>b</p>" )
+ .parent();
+ equal( div.find("*").length, 3, "added 2 paragraphs after inner div" );
+});
+
testIframeWithCallback( "buildFragment works even if document[0] is iframe's window object in IE9/10 (#12266)", "manipulation/iframe-denied.html", function( test ) {
expect( 1 );