Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix #13019. Disconnected nodes with .replaceWith are a noop. #1062

wants to merge 1 commit into


None yet
2 participants

dmethvin commented Dec 8, 2012

We should just do nothing with disconnected elements here, as we do with .before() and .after(). It's actually more compatible with older versions I think, although some of that may be due to bugs in those versions. In any case it's -19 gzip so there's that. 😺

Compare this (1.8.3) to current -git:



gibson042 commented Dec 8, 2012

The behavior is documented ("As of jQuery 1.4, .replaceWith() can also work on disconnected DOM nodes"), but I think abandoning it without deprecation can be justified by the same logic we're using with .before and .after.

The case in your fiddle (set containing disconnected elements but first element connected) appears never to have worked, but I suspect that if anyone ever took advantage of this logic in .replaceWith it was on sets containing only disconnected elements. Still, that's what jquery-compat is for, right?


dmethvin commented Dec 9, 2012

Ugh. Yeah, it seems strange to allow this one exception for disconnected nodes when we've eliminated the others. With disconnected elements .replaceWith() works more like the Array .splice() method and it would seem to make more sense to provide Array-like methods in a plugin to do those things.

Also, we're saying "disconnected" in this discussion but we really mean "either has no parent or has a fragment as a parent". I wonder if we should just remove isDisconnected() and look for elem.parentNode instead, allowing someone to treat fragments as containers for manipulation.

@dmethvin dmethvin closed this in f8f52cf Dec 9, 2012

@mescoda mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014

@dmethvin dmethvin Fix #13019. Disconnected nodes with .replaceWith are a noop. Close gh… 6edc4ce

@mescoda mescoda pushed a commit to mescoda/jquery that referenced this pull request Nov 4, 2014

@dmethvin dmethvin Ref #13019 and gh-1062. Use parentNode check instead of isDisconnecte…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment