From 78c1560065e664213ac0cbea7518d442a58b0018 Mon Sep 17 00:00:00 2001 From: dcooper Date: Fri, 7 Sep 2012 14:12:24 -0400 Subject: [PATCH] Fix #9960, allow manipulation for parent document nodes. Close gh-924. --- AUTHORS.txt | 1 + src/manipulation.js | 4 ++-- test/unit/manipulation.js | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index dea7ef995..834b1163a 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -154,3 +154,4 @@ Allen J Schmidt Jr Marcel Greter Matthias Jäggli Yiming He +Devin Cooper diff --git a/src/manipulation.js b/src/manipulation.js index b179dab2e..509daa6e5 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -126,7 +126,7 @@ jQuery.fn.extend({ append: function() { return this.domManip(arguments, true, function( elem ) { - if ( this.nodeType === 1 || this.nodeType === 11 ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { this.appendChild( elem ); } }); @@ -134,7 +134,7 @@ jQuery.fn.extend({ prepend: function() { return this.domManip(arguments, true, function( elem ) { - if ( this.nodeType === 1 || this.nodeType === 11 ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { this.insertBefore( elem, this.firstChild ); } }); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 1d0dc4538..3a1d598d2 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -527,6 +527,24 @@ test("append(Function) with incoming value", function() { QUnit.reset(); }); +test("replaceWith on XML document (#9960)", function () { + expect( 1 ); + + var newNode, + xmlDoc1 = jQuery.parseXML(""), + xmlDoc2 = jQuery.parseXML(""), + xml1 = jQuery( xmlDoc1 ), + xml2 = jQuery( xmlDoc2 ), + scxml1 = jQuery( ":first", xml1 ), + scxml2 = jQuery( ":first", xml2 ); + + scxml1.replaceWith( scxml2 ); + + newNode = jQuery( ":first>state[id='provisioning3']", xml1 ); + + equal( newNode.length, 1, "ReplaceWith not working on document nodes." ); +}); + test("append the same fragment with events (Bug #6997, 5566)", function () { var doExtra = !jQuery.support.noCloneEvent && document["fireEvent"]; expect(2 + (doExtra ? 1 : 0)); -- 2.39.5