MatthewMueller/cheerio — comment on commit 5320d639f031e1cce126fe3fe44273e0fe955da9
File: lib/api/manipulation.js line 168
By ironchefpython:

Ah, found the "proper" behavior.

> The .replaceWith() method, like most jQuery methods, returns the jQuery object so that other methods can be chained onto it. However, it must be noted that the original jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.

However, http://bugs.jquery.com/ticket/7246 notes the discrepancy, but there is no feedback from the developers on whether the inverse behavior on nodes disconnected from the DOM is intended.