diff --git a/lib/api/manipulation.js b/lib/api/manipulation.js index 4ae89db05f..bbab180fa8 100644 --- a/lib/api/manipulation.js +++ b/lib/api/manipulation.js @@ -157,17 +157,12 @@ var remove = exports.remove = function(selector) { }; var replaceWith = exports.replaceWith = function(content) { - var dom = makeDomArray(content); - domEach(this, function(i, el) { var parent = el.parent || el.root, siblings = parent.children, + dom = makeDomArray(_.isFunction(content) ? content.call(el, i, el) : content), index; - if (_.isFunction(content)) { - dom = makeDomArray(content.call(el, i, el)); - } - // In the case that `dom` contains nodes that already exist in other // structures, ensure those nodes are properly removed. updateDOM(dom, null); diff --git a/test/api.manipulation.js b/test/api.manipulation.js index 1e5cce9fc5..7affc37c98 100644 --- a/test/api.manipulation.js +++ b/test/api.manipulation.js @@ -583,6 +583,13 @@ describe('$(...)', function() { expect($.html($src)).to.equal('