diff --git a/lib/api/manipulation.js b/lib/api/manipulation.js index 2f5ba87b22..d17f0dda1a 100644 --- a/lib/api/manipulation.js +++ b/lib/api/manipulation.js @@ -646,7 +646,10 @@ exports.replaceWith = function (content) { // Completely remove old element uniqueSplice(siblings, index, 1, dom, parent); - el.parent = el.prev = el.next = null; + + if (dom.indexOf(el) < 0) { + el.parent = el.prev = el.next = null; + } }); return this; diff --git a/test/api/manipulation.js b/test/api/manipulation.js index 27850409dd..2bf629635b 100644 --- a/test/api/manipulation.js +++ b/test/api/manipulation.js @@ -1391,6 +1391,16 @@ describe('$(...)', function () { expect($.html($src)).to.equal('